I have had this problem before but I can't figure it out for the life of me. This should be an easy one for all you php gurus.
(The error is listed below in the "show cart" section)
<?
session_start();
ob_start();
$ipaddress = getenv('REMOTE_ADDR');
echo $ipaddress."<br>";
echo "\$sessionver: ".$sessionver."<br>";
if ($sessionver == 2)
{
$session = md5(uniqid(rand()));
setcookie("sessionid", $session, time() + 35);
}
if ($sessionver == 3)
{
$session = $HTTP_COOKIE_VARS["sessionid"];
}
$table = "inventory";
@ $db = mysql_pconnect("localhost","user","pass");
if (!$db) { echo "Error: Could not connect to database."; exit; }
mysql_select_db("shop");
if ($quantity < 1)
{
echo "Error: You did not enter a valid quantity."; exit;
}
//**add to cart***
$query = "insert into carts values
('".$session."', ".$product.", ".$quantity.")";
$result = mysql_query($query);
//**show cart**
$query = "select from carts where session = '".$session."')";
$result = mysql_query($query);
$num_results = mysql_num_rows($result); /Gives this: "Supplied argument is not a valid MySQL result resource"*/
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo ($i+1).". Product: ";
echo htmlspecialchars (stripslashes($row["product"]));
echo "<br>Quantity: ";
echo htmlspecialchars (stripslashes($row["qty"]));
}
?>