Forum Home
Press F1
 
Thread ID: 58086 2005-05-21 05:56:00 PHP Mysql help insert statement not inserting Morgenmuffel (187) Press F1
Post ID Timestamp Content User
357193 2005-05-21 05:56:00 Hi All

having a bit of a problem with the following code



mysql_select_db($dbname);
$query3 = ("insert into a_orders (session_Id, customer_name, customer_location, email) values ('" . $bob . "','" . $customer_name . "','" . $customer_location . "','" . $e_mail . "'");
echo "insert into a_orders(session_Id, customer_name, customer_location, email) values ('" . $bob . "','" . $customer_name . "','" . $customer_location . "','" . $e_mail . "')";
mysql_query($query3, $db);
$order_ID = mysql_insert_id();
echo $order_ID<br>';



now before you ask
$bob and $customer_name and $customer_location and $e_mail all show up correctly in the echoed out string, so the problem isn't with them

The table I am inserted was created as below


CREATE TABLE `a_orders` (
`order_Id` int(11) unsigned NOT NULL auto_increment,
`session_Id` varchar(60) default NULL,
`customer_name` varchar(50) default NULL,
`customer_location` varchar(40) default NULL,
`email` varchar(150) default NULL,
`price` decimal(5,2) default NULL,
`price_adj` decimal(5,2) default '0 . 00',
`order_valid` varchar(50) default NULL,
`transaction_Id` varchar(50) default NULL,
`error_code` varchar(6) default NULL,
`error_message` varchar(40) default NULL,
PRIMARY KEY (`order_Id`),
UNIQUE KEY `id` (`order_Id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;



the thing is I am not getting any errors, just nothing happens, I have checked the a_orders database and it is empty
the $order_ID = mysql_insert_id();
returns 0 which means the previous query does not generate an AUTO_INCREMENT value

any help greatly appreciated
Morgenmuffel (187)
357194 2005-05-21 07:06:00 Try removing the brackets from around your query def: $query3. wuppo (41)
357195 2005-05-21 07:31:00 Try replacing your posted code with the following:

mysql_select_db($dbname);

$query3 = ("INSERT INTO a_orders (session_Id, customer_name, customer_location, email) VALUES('$bob', '$customer_name', '$customer_location', '$e_mail'");
$result = mysql_query($query3) or die('<p>MySQL Error: ' . mysql_error() . '</p>');;
$order_ID = mysql_insert_id();
echo "$order_ID<br />";
sal (67)
357196 2005-05-21 08:59:00 Hi all got it working, turns out I was missing a clossing bracket


$query3 = ("insert into a_orders (session_Id, customer_name, customer_location, email) values ('" . $bob . "' ,'" . $customer_name . "' ,'" . $customer_location . "' ,'" . $e_mail . "' )");



But if you're all still there I could do with a bit more help I am getting the following error


Resource id #14result query

SELECT
cookieId, itemId, sizeId, optId, qty, product_name, option_name, size_size, nz_price
FROM
a_cart, a_product, a_option, a_size
where a_cart . cookieId = '37495091adfa5d1c14d6e5c21f8ae9be'
AND a_cart . sizeId = a_size . size_ID
AND a_cart . optId = a_option . option_ID
AND a_cart . itemId = a_product . product_ID

got past result query

You have an error in your SQL syntax . Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #14' at line 1

You have an error in your SQL syntax . Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #14' at line 1





mysql_query($query3, $db);
$order_ID = mysql_insert_id();
echo $order_ID . '<--Order ID<br>';
//$totalCost = 0;
$result_query7 = mysql_query("SELECT cookieId, itemId, sizeId, optId, qty, product_name, option_name, size_size, " . $local_price . "_price FROM a_cart, a_product, a_option, a_size where a_cart . cookieId = '" . $bob . "' AND a_cart . sizeId = a_size . size_ID AND a_cart . optId = a_option . option_ID AND a_cart . itemId = a_product . product_ID");

echo $result_query7 . 'result query<br>';
//echo the above out to find its resource ID
echo "SELECT cookieId, itemId, sizeId, optId, qty, product_name, option_name, size_size, {$local_price}_price FROM a_cart, a_product, a_option, a_size where a_cart . cookieId = '" . $bob . "' AND a_cart . sizeId = a_size . size_ID AND a_cart . optId = a_option . option_ID AND a_cart . itemId = a_product . product_ID";
echo "<br>got past result query<br>";//gets to here then crashes
$result = mysql_query($result_query7, $db) or die(mysql_error());
Morgenmuffel (187)
357197 2005-05-21 13:30:00 Thanks for all the help:thumbs:

I now have it all working
Morgenmuffel (187)
1