General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 7th, 2004, 05:43 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
fetch array not working

Hi guys,

can u guys take a look at my code ?? before this, i used this code in a shopping cart thank you page and it works,,, but now, when i try to do another shopping cart by using the same code, it does't work anymore...

i tried to echo the session id and the id displayed does exist in my database, but why there is no data displayed when i try to fetch the result from the database and send out the email ???

did i miss something or i put the code wrongly ??? but it does work previously.., it even works on the previous file <- the file the user can click to confirm the order..

it seems like after i added the code for mail function, then everything doesn't seem to work anymore..

please advise... thanks

<?
session_start();
include "db.php";
$s = mysql_connect($dbServer, $dbUser, $dbPass) or die("Query failed: $query<br><br>" . mysql_error());
$d = mysql_select_db($dbName, $s) or die("Query failed: $query<br><br>" . mysql_error());


function NewCart()
{
if (isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
}

$cartId = NewCart();
$result = mysql_query("select* from perfume_cart inner join perfume_items on perfume_cart.itemId = perfume_items.itemId where perfume_cart.cookieId = '".$cartId."' order by perfume_items.itemName asc") or die (mysql_error());


$subject ="Online Shopping Order";
$to = "email@sas.com";


$contents .= "-----\n";
$contents .= "Order\n";
$contents .= "-----\n";


while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);

$contents .="Quantity: {$row['qty']}\n";
$contents .="Item: {$row['itemName']}\n";
$contents .="Price per item: USD";
$contents .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents .="Total amount: USD {$totalCost}\n\n";



mail($to,$subject,$contents);


################################################## ################################################


$result = mysql_query("select* from perfume_cart inner join perfume_items on perfume_cart.itemId = perfume_items.itemId where perfume_cart.cookieId = '".$cartId."' order by perfume_items.itemName asc") or die (mysql_error());

$subject1="Order confirmation";
$to1="$email";

$contents1 .= "Your order:\n";
$contents1 .= "-----------\n";


while($row = mysql_fetch_array($result)) {
$totalCost1 += ($row["qty"] * $row["itemPrice"]);

$contents1 .="Quantity: {$row['qty']}\n";
$contents1 .="Item: {$row['itemName']}\n";
$contents1 .="Price per item: USD";
$contents1 .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents1 .="Total amount: USD {$totalCost1}\n\n";


mail($to1,$subject1,$contents1);

echo 'info';
echo $cartId;

//no output displayed in this part =(
while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);

echo "Quantity: {$row['qty']}\n";
echo "Item: {$row['itemName']}\n";
echo "Price per item: USD";
echo number_format($row['itemPrice'], 2,'.', '.') . "\n\n";
}


?>

Reply With Quote
  #2  
Old January 7th, 2004, 08:18 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Have you tried printing out your query and running it at the command line? I see for example that you appear to be lacking a space between "select" and "*". Perhaps that causes a warning or is ok syntactically but doesn't return any results. Does this work when you take the mail functionality out and then break again when you put it back in?

Reply With Quote
  #3  
Old January 8th, 2004, 10:29 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
hi guys,

can somebody take a look at my code.. it is weird coz sometimes the code is working and sometimes, it doesn't.. even i put a spacing in the select query it doesn't make any difference though

my code:
<?
session_start();

$dbServer = "";
$dbUser = "user";
$dbPass = "pass;
$dbName = "my_onlinestore";

global $dbServer;
global $dbUser;
global $dbPass;
global $dbName;

$s = mysql_connect($dbServer, $dbUser, $dbPass) or die("Query failed: $query<br><br>" . mysql_error());
$d = mysql_select_db($dbName, $s) or die("Query failed: $query<br><br>" . mysql_error());


function NewCart()
{
//generate an encrypted string and set it as cookie
if (isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// session_start();
// setcookie("cartId", session_Id(), time() + ((3600 * 24) *7));

return session_id();

//echo "error occurred, please contact administrator or try to use a new cart";
//exit();
}
}

$result = mysql_query("select * from perfume_cart inner join perfume_items on perfume_cart.itemId = perfume_items.itemId where perfume_cart.cookieId = '".$cartId."' order by perfume_items.itemName asc") or die(mysql_error());


$totalCost = "0";
$contents .= "-----\n";
$contents .= "Order\n";
$contents .= "-----\n";

$cartId = NewCart();

$row = mysql_fetch_array($result);
while($row) {
$totalCost += ($row["qty"] * $row["itemPrice"]);

$contents .="Quantity: {$row['qty']}\n";
$contents .="Item: {$row['itemName']}\n";
$contents .="Price per item: USD";
$contents .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents .="Total amount: USD {$totalCost}\n\n";
echo $cartId;
echo 'haha -- ';
echo $contents;
echo '<br><br><br><br>';


################################################## ################################################


$cartId = NewCart();
$result2 = mysql_query("select* from perfume_cart inner join perfume_items on perfume_cart.itemId = perfume_items.itemId where perfume_cart.cookieId = '".$cartId."' order by perfume_items.itemName asc");



//forcustomer
$contents1 .= "Thanks \n\n";


$contents1 .= "------------------------------------\n";
$contents1 .= "Online Order Form\n";
$contents1 .= "------------------------------------\n";

$contents1 .= "Your order:\n";
$contents1 .= "-----------\n";


while($row = mysql_fetch_array($result)) {
$totalCost1 += ($row["qty"] * $row["itemPrice"]);

$contents1 .="Quantity: {$row['qty']}\n";
$contents1 .="Item: {$row['itemName']}\n";
$contents1 .="Price per item: USD";
$contents1 .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents1 .="Total amount: USD {$totalCost1}\n\n";
echo $cartId;
echo 'haha -- ';
echo $contents1;


?>


when i echo the output, it display all string except for the output inside the while loop.. is it i have prob with my sql fetch array or my while loop ??? it does work in another file using the same code but why this is not working ??

p.s: actually i wanna send the output to two separate email addresses by using mail function later..

please advise..

Reply With Quote
  #4  
Old January 8th, 2004, 11:54 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
A quick glance at your code and I saw this (after all the # symbols):

Code:
$result2 = mysql_query("select* from perfume_cart inner join perfume_items on perfume_cart.itemId = perfume_items.itemId where perfume_cart.cookieId = '".$cartId."' order by perfume_items.itemName asc");

...

while($row = mysql_fetch_array($result)) {

Reply With Quote
  #5  
Old January 9th, 2004, 12:01 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
hi, i have changed that but it is still not working.. actually i did use $result but it wasn't working.,., so i change to $result2

any other mistakes i done >

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > fetch array not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT