This is a simple shopping cart I found somewhere, a long time ago and now in need of to make an ordering system of. But it for some or other bizarre reason not insert all of the fields I feed it!
My functions below:
function get_categoryid($pid){
$result=mysql_query("select product_category_id from shopping_products where serial=$pid") or die("select product_category_id from shopping_products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['product_category_id'];
}
function get_thecategory($pid){
$result=mysql_query("select product_category_title from shopping_products where serial=$pid") or die("select product_category_title from shopping_products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['product_category_title'];
}
}
Here is the PHP code where it gets inserted into the "shopping_order_detail" table after the clients has filled in his/her info.
if ( isset($_REQUEST['command']) && $_REQUEST['command']=='update'){
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$address=$_REQUEST['address'];
$phone=$_REQUEST['phone'];
$loyalty=$_REQUEST['loyalty'];
$result=mysql_query("insert into shopping_customers values('','$name','$email','$address','$phone','$loyalty')");
$customerid=mysql_insert_id();
$date=date('Y-m-d');
$result=mysql_query("insert into shopping_orders values('','$date','$customerid')");
$orderid=mysql_insert_id();
/* ---- below my problem i think --- */
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$pcategoryid=get_categoryid($pid);
$pcategory=get_thecategory($pid);
$pvendor=get_thevendor($pid);
mysql_query("INSERT INTO shopping_order_detail VALUES($orderid,$pid,$q,$price,$pcategoryid,$pcategory,$pvendor)");
echo "vendor -" . $pvendor . " Order ID - " . $orderid . " - Product ID - " . $pid . " - Category ID ". $pcategoryid ." - Price R ". $price .".00 - Quantity ". $q. "- Category Title: ". $pcategory ."<Br>";
}
echo "<br>=======================================================================================<br>";
echo "<br>Data echoed above this works fine.. and pulls the correct shopping items<br>";
echo "<br>Sucess ......Data Inserted!<br>";
die('Thank You! your order has been placed');
}
Here is my problem !
The "$pcategoryid" is inserted into the table , But whatever amount of fields i ad after this not only does not insert, but it also for some or other reason prevent any information being inserted with this piece of script.
To recap my problem: If I remove "$pcategory" and "$pvendor" from the script the data gets inserted. if I add these two fields in question then the script does not insert, But/And it does not give any error messages.
My "Echo === etc" commands at the bottom of the script shows me that my script is working as it shows those two fields in question when it cycles through list of items
I have set my PHP error codes this way:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
Is it some kind of restriction in Mysql as the Table in question does not have a primary key? I am at a loss for a solution!
Please, Any help will be appreciated thank you.