|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
while($row = mysql_fetch_array($result))
hello everyone
im new to php so any help will be much appreciated I have the error message: Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result resource line 38 and also Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result resource line 140 i have checked my database connection and that seems to be ok because my products.php works fine. RemoveItem($_GET["itemId"]); ShowCart(); break; } default: { ShowCart(); } } function AddItem($itemId, $qty) { global $dbServer, $dbUser, $dbPass, $dbName; $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); $result = mysql_query("select count(*) from cart where cookieId = '" . GetCartID() . "' and itemId = $itemId"); $row = mysql_fetch_row($result); (line 38) $numRows = $row[0]; if($numRows == 0) { @mysql_query("insert into cart(cookieID, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)"); } else { // This item already exists in the users cart, // we will update it instead UpdateItem($itemId, $qty); } } function UpdateItem($itemId, $qty) { global $dbServer, $dbUser, $dbPass, $dbName; // Get a connection to the database $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); if($qty == 0) { // Remove the item from the users cart RemoveItem($itemId); } else { mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId"); } } function RemoveItem($itemId) { global $dbServer, $dbUser, $dbPass, $dbName; // Get a connection to the database $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId"); } function ShowCart() { // Gets each item from the cart table and display them in // a tabulated format, as well as a final total for the cart global $dbServer, $dbUser, $dbPass, $dbName; // Get a connection to the database $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); $totalCost = 0; $result = mysql_query("select * from cart inner join items on cart.itemId = item.itemId where cart.cookieId= '" . GetCartId() . "' order by item.name asc"); ?> <html> <head> <title> Your Shopping Cart </title> <script language="JavaScript"> function UpdateQty(item) { itemId = item.name; newQty = item.options[item.selectedIndex].text; document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty; } </script> </head> <body bgcolor="#ffffff"> <h1>Your Shopping Cart</h1> <form name="frmCart" method="get"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td width="15%" height="25" bgcolor="red"> <font face="verdana" size="1" color="white"> <b>Qty</b> </font> </td> <td width="55%" height="25" bgcolor="red"> <font face="verdana" size="1" color="white"> <b>Product</b> </font> </td> <td width="20%" height="25" bgcolor="red"> <font face="verdana" size="1" color="white"> <b>Price Each</b> </font> </td> <td width="10%" height="25" bgcolor="red"> <font face="verdana" size="1" color="white"> <b>Remove?</b> </font> </td> </tr> <?php while($row = mysql_fetch_array($result)) (line 140) { // Increment the total cost of all items $totalCost += ($row["qty"] * $row["price"]); ?> thanks |
|
#2
|
||||
|
||||
|
In the past I've found Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result generally means my query is wrong...
try outputting your SQL query to make sure it actually reads the way you want it to... You may want to change this line to read: $result = @mysql_query("select count(*) from cart where cookieId = '" . GetCartID() . "' and itemId = $itemId") or die("Error ".mysql_errno().": ".mysql_error()); |
|
#3
|
|||
|
|||
|
i ve added the line of code you suggessted and know i get the following error
Error 1064: You have an error in your SQL syntax near '' at line 1 thanks |
|
#4
|
||||
|
||||
|
check to make sure GetCartID() is returning the proper information... I would assume its not...
A common debugging technique that I use is to make the query a variable... it makes it easier to print if there's an error... Based on the code I gave you before: $sql="select count(*) from cart where cookieId = '" . GetCartID() . "' and itemId = $itemId"; $result = @mysql_query($sql) or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $sql"); bolding is there to show my changes... |
|
#5
|
|||
|
|||
|
thanks MadCowDzz
your debugging technique was helpful i had a problem with my query. It works now! |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > while($row = mysql_fetch_array($result)) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|