hi, i have a shopping cart with this SQL queries: <?php session_start(); $sessionid = session_id(); $code = $_POST["code"]; $model = $_POST["model"]; $descr = $_POST["descr"]; $pricer = $_POST["pricer"]; $qty = $_POST["qty"]; $cart = $_POST["cart"]; If($qty == "") $qty=1; ?> <?php if ( !empty($cart) ) { switch($cart) { case "add": $sql= "INSERT INTO cart (sessionid, code, model, descr, pricer, qty) VALUES ('$sessionid','$code','$model','$descr','$pricer','$qty')"; break; case "del": $sql= "DELETE FROM cart WHERE code='$code'"; break; case "upd": $sql= "UPDATE cart SET qty='$qty' WHERE code='$code'"; break; } if ( !empty($sql) ) { $res= mysql_query($sql); // handle any query errors here } } $result = mysql_query("SELECT * FROM cart WHERE sessionid='".$sessionid."' ORDER BY pricer"); mysql_close($con); ?> PHP: i want to display a message when the visitor adds a product for second time in the cart. when the product is already in the cart i want to display a message like that: "the product is already in the cart" can anybody give a litle help? thanks in advance.
<?phpsession_start();$sessionid = session_id();$code = $_POST["code"];$model = $_POST["model"];$descr = $_POST["descr"];$pricer = $_POST["pricer"];$qty = $_POST["qty"];$cart = $_POST["cart"];If($qty == "") $qty=1; ?> if ($cart=="add") { $result2=mysql_query("SELECT * FROM cart WHERE sessionid='".$sessionid."' ORDER BY pricer"); $tt=0; while ($row = mysql_fetch_array($result2)) { if ($row["code"]==$code) { $tt=1; } } //while if ($tt==1) echo "product allready added"; } <?php if ( !empty($cart) ) { switch($cart) { case "add": $sql= "INSERT INTO cart (sessionid, code, model, descr, pricer, qty) VALUES ('$sessionid','$code','$model','$descr','$pricer','$qty')"; break; case "del": $sql= "DELETE FROM cart WHERE code='$code'"; break; case "upd": $sql= "UPDATE cart SET qty='$qty' WHERE code='$code'"; break; } if ( !empty($sql) ) { if($tt==0) $res= mysql_query($sql); // handle any query errors here } } $result = mysql_query("SELECT * FROM cart WHERE sessionid='".$sessionid."' ORDER BY pricer"); mysql_close($con); ?> Code (markup):