Page 1 of 1

quick question about shopping cart

Posted: Tue Jul 27, 2004 10:59 am
by SJanis
feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


sorry...but i have a quick question...my shopping cart that i built of the macromedia persistent cart example... works perfectly fine when i'm adding items numbers to it such as 1000354, 3500035, or 3053535, but as soon as i add a letter to the end of one of those part numbers...lets say the number is....1004400F, (http://127.0.0.1/testshopping/cart.php? ... &qty=1) i get a Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource error....if anyone could help i would greatly appreciate it...thank you very much....

this is the cart.php..if this helps..

Code: Select all

<?php

include("db.php");

switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "update_item":
{
UpdateItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["id"]);
ShowCart();
break;
}
case "default":
{
ShowCart();
}
}

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);

// Check if this item already exists in the users cart table
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
$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, 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)
{
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead

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)
{
// Uses an SQL delete statement to remove an item from
// the users cart

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 data_det on cart.itemId = data_det.itemId where cart.cookieId = '" . GetCartId() . "' order by data_det.itemManu asc");
?>

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Jul 27, 2004 11:06 am
by feyd
it's likely the part number is stored as a number, or the query returned zero records that matched.. you have a comma in your query string, could this be screwing it up?

Posted: Tue Jul 27, 2004 12:17 pm
by John Cartwright
why would you want to add a letter to it?

Posted: Tue Jul 27, 2004 12:44 pm
by SJanis
the part number calls for a letter in it....such as maybe 104440F or HT 2013....i'm still getting the same mysql_fetch_row(): supplied argument is not a valid MySQL result resource even after changing the type of itemId in my cart table from an int...to a varchar.....

Posted: Tue Jul 27, 2004 12:51 pm
by feyd
you have an error in you sql syntax now that you placed a letter in there.. add quotes around $itemId in the queries.

Posted: Tue Jul 27, 2004 1:17 pm
by SJanis
thank you feyd...i did that too all of them and it worked perfect...i really appreciate you help...thanks again