I am trying to make a script so that if a product already exits in a shopping cart instead of adding it again so it appears twice it updates the current product in the shopping cart with the new quantity.
I have this bit working the problem lies with the fact that the else part of the statement isn't working, so if the product doesn't exist in the cart it won't add it.
Any help appreciated
Code:<?php session_id(); session_start(); include("database/database.php"); $qty = $_POST['qty']; $prodnum = $_POST['prodnum']; $sess = session_id(); if (empty($qty) || !is_numeric($qty)) {include("error.php"); } $query = "SELECT * from carttemp WHERE sess = '$sess'"; $results = mysql_query($query) or die(mysql_error()); $numrows = mysql_num_rows($results); if ($numrows == 1) {while ($row = mysql_fetch_array($results)) { $prodnumexists = $row[prodnum]; $currentquan = $row[quan]; if ($prodnumexists == $prodnum) {$updateqty = $currentquan + $qty; mysql_query("UPDATE carttemp SET quan = '$updateqty' WHERE prodnum = '$prodnum'"); }}} else { $query1 = "INSERT INTO carttemp (sess, quan, prodnum) VALUES ('$sess','$qty','$prodnum')"; $results1 = mysql_query($query1) or die(mysql_error()); } include ("cart.php"); exit; ?>







Bookmarks