
August 3rd, 2003, 12:30 PM
|
|
Junior Member
|
|
Join Date: Aug 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
An other problem with shopping cart
Hello everybody,
I'm using the shopping cart tutorial of this site. But it is that I have some difficulties. In my data base, I have a table "cart" which contains information on each item stored by the user, with the champs(cartId, cookieId, ref_prod, qty). At the time of the use of the AddItem function of which here the code
PHP Code:
function AddItem($itemId, $qty)
{
// Will check whether or not this item
// already exists in the cart table.
// If it does, the UpdateItem function
// will be called instead
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$cartid = GetCartId();
// Check if this item already exists in the users cart table
// requête posant problème
$query = "select count(*) from cart where cookieId = '" . GetCartId() . "' and ref_prod = $itemId";
$result = mysql_query($query) /*or die("Couldn't execute query")*/;
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0) {
// This item doesn't exist in the users cart,
// we will add it with an insert query
@mysql_query("insert into cart(cookieId, ref_prod, qty) values('" . GetCartId() . "', $itemId, $qty)");
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($itemId, $qty);
}
}
I have a problem with the request query, in fact after several test it is as if the table cart did not exist. I have the error message according to:
Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result resource
When I make an echo of the request "query" the result:
count(*) from cart where cookieId = ' bd0791c67082e8c34a07ca4b6a006a9b' and ref_prod = 12
I have done a select cookieId on this one (the table cart) and tried to post the result, but anything. Whereas the table exists indeed. I will like to know which could be the problem.
Thank you in advance
|