Hi,
I was told that to use the get function when using characters rather than numbers you need extra ’ and " to use the get function. Like this:
$prod_info = mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = '".$_GET['product']."'"));
I am now editing this code and I have a problem. How should I edit the code to work - it used to work with numbers. Now I am using characters it does not work:
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["product"], $_GET["quantity"]);
ShowCart();
break;
}
case "update_item":
{
UpdateItem($_GET["product"], $_GET["quantity"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["product"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
but there is an error in the code below on line 4. I think line 3 might be the reason line 4 is having a problem. But as I suggest above the get function is not correct now. How should the get function be written now that it includes characters?
function AddItem($productid, $quantity){
//The main part of the AddItem function checks whether or not this item already exists in the users cart. If it does, then //its quantity field is updated and it isn't added again:
$query = mysql_query("SELECT COUNT(*) FROM cart where cookieid = '" . GetCartId() . "' and product = $productid");
$num = mysql_fetch_row($query);
$quant = $num[0];
if($quant == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
@mysql_query("insert into cart(cookieid, product, quantity) values('" . GetCartId() . "', $product, $quantity)");
}
else
{
@mysql_query("update cart set quantity = quantity + '$quantity' where product = $productid");
// This item already exists in the users cart,
// we will update it instead
//Looking at the code above, we can see that if $numRows equals zero (i.e. the item isn't already in the users cart) then //the item is added to the cart table. If not, the items quantity field is updated by calling the UpdateItem function,
//which is described below.
//UpdateItem accepts two parameters, in the same way that the AddItem function does:
}
}