Newbie---PhP MySQL INSERT query syntax problem...why?
Posted: Sat Jun 21, 2003 8:39 pm
I have written the following code for a simple shopping cart add function. (This is a learning site, and I know the code isn't really tight).
The problem I'm fighting now is that I keep getting a syntax error on the insert statement on line 33. The insert values are from the $row_cart_add array, and I believe they are assigned properly... Anyway could someone take a look and tell me why it keeps choking at the INSERT statement?
If you want to see it in action, the URL is http://www.sgthost.com. just log in as U=test P=test and try to add something to the cart. (The URL is on my personal server in asia, and make not load very quickly at all...sorry)
Any suggestions appreciated.
Here is the PHP code.
Thanks
---------------------
SteedVLX
The problem I'm fighting now is that I keep getting a syntax error on the insert statement on line 33. The insert values are from the $row_cart_add array, and I believe they are assigned properly... Anyway could someone take a look and tell me why it keeps choking at the INSERT statement?
If you want to see it in action, the URL is http://www.sgthost.com. just log in as U=test P=test and try to add something to the cart. (The URL is on my personal server in asia, and make not load very quickly at all...sorry)
Any suggestions appreciated.
Here is the PHP code.
Code: Select all
<?php
<?php require_once('../Connections/kb_conn.php'); ?>
<?php
$colname_cart_add = "1";
if (isset($HTTP_GET_VARS['prod_id_index'])) {
global $colname_cart_add;
$colname_cart_add = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['prod_id_index'] : addslashes($HTTP_GET_VARS['prod_id_index']);
}
mysql_select_db($database_kb_conn, $kb_conn);
$query_cart_add = sprintf("SELECT * FROM products_tbl WHERE prod_id_index = %s", $colname_cart_add);
$cart_add = mysql_query($query_cart_add, $kb_conn) or die(mysql_error());
$row_cart_add = mysql_fetch_assoc($cart_add);
$totalRows_cart_add = mysql_num_rows($cart_add);
?>
<?php
global $error_text;
global $error_state;
if (!$session_usernumber) {
$error_state="1";
$error_text="You Must Log In to Use the Shopping Cart";
echo "$error_text";
}
else {
$query_cart = sprintf("SELECT * FROM cart WHERE cart_prod_id_index = $colname_cart_add and usernumber = $session_usernumber");
$cart = mysql_query($query_cart, $kb_conn) or die(mysql_error());
$row_cart = mysql_fetch_assoc($cart);
$totalRows_cart = mysql_num_rows($cart);
if ($totalRows_cart > 0) {
$error_state="2";
$error_text="That Item is Already in Your Cart or Wishlist";
echo "$error_text";}
else {
$line_total = 'cart_add.cart_quantity' * 'cart_add.prod_sell_price_jpy';
$query = "INSERT INTO cart VALUES (NULL, $session_usernumber,$session_user,'0',$row_cart_add[prod_id_index],$row_cart_add[prod_kb_part_num],'1',$row_cart_add[prod_sell_price_jpy],$row_cart_add[prod_e_desc],$row_cart_add[prod_j_desc],$line_total,curdate(),$row_cart_add[prod_discount_percent]";
$result = mysql_query($query)or die(mysql_error());
$error_state="0";
$error_text="Successful!! Item has been added to your cart.";
echo "$error_text";
}
}
?>
?>---------------------
SteedVLX