|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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"; } ?> |
|
#2
|
||||
|
||||
|
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?
|
|
#3
|
|||
|
|||
|
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.. |
|
#4
|
||||
|
||||
|
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)) {
|
|
#5
|
|||
|
|||
|
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 > |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > fetch array not working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|