Diether Posted January 28, 2013 Share Posted January 28, 2013 hi guys Good day, , i have two data from same form that i want to insert in the different table in my database. 1. data came from the form( firstname,lastname,phonenumber etc.) 2. data came from session variable(item id, quantity, etc) im getting this error, please help me to solve this. thanks Notice: Undefined variable: itemId in C:\xampp\htdocs\sample\delivery_details.php on line 16 Notice: Undefined variable: qty in C:\xampp\htdocs\sample\delivery_details.php on line 17 Notice: Undefined variable: itemid in C:\xampp\htdocs\sample\delivery_details.php on line 19 Notice: Undefined variable: qty in C:\xampp\htdocs\sample\delivery_details.php on line 19 the code i use: <?php if (isset($_POST['submit'])){ $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $phoneNumber = $_POST['phoneNumber']; $emailAddress = $_POST['emailAddress']; $Address = $_POST['Address']; $query = mysql_query("INSERT INTO customer (id, first_name, last_name, phone_number,email_address,address) VALUES ('','$firstName', '$lastName',$phoneNumber,'$emailAddress','$Address')"); $getID = mysql_query("SELECT id FROM customer where first_name = '$firstName' and last_name = '$lastName'"); $num_row = mysql_num_rows($getID); if($num_row !=0){ while($row = mysql_fetch_array($getID)){ $_SESSION["cart_array"]["item_id"] = $itemId; $_SESSION["cart_array"]["quantity"] = $qty; $sql1 = mysql_query("INSERT INTO order (id,quantity,item_id) VALUES ('',$itemid,$qty )"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/273750-helpundefined-variable-when-saving-session-data-to-db/ Share on other sites More sharing options...
Jessica Posted January 28, 2013 Share Posted January 28, 2013 As it says, you haven't defined $qty of $itemId. Where are they coming from? However, I can't follow the logic of your code. What are you trying to do? Finally, you should never run queries in loops. Quote Link to comment https://forums.phpfreaks.com/topic/273750-helpundefined-variable-when-saving-session-data-to-db/#findComment-1408791 Share on other sites More sharing options...
Diether Posted January 28, 2013 Author Share Posted January 28, 2013 Heres my problem. i have two data from same form that i want to insert in the different table in my database. 1. data came from the form( firstname,lastname,phonenumber etc.) 2. data came from session variable(item id, quantity, total etc) when the customer clicks the FINISH button, the data will be insert in the two separate tables in the database. Here's my screenshot of my form: http://img6.uploadho...96ab1f360bd.jpg that code above is the solution to my problem. Quote Link to comment https://forums.phpfreaks.com/topic/273750-helpundefined-variable-when-saving-session-data-to-db/#findComment-1408794 Share on other sites More sharing options...
Jessica Posted January 28, 2013 Share Posted January 28, 2013 You got 1 of 3. Your code still doesn't make sense for your described problem. I think you need to use mysql_last_insert_id(), and not run a select and a loop. You should have TWO INSERTS and that's it. As it says, you haven't defined $qty of $itemId. Where are they coming from? However, I can't follow the logic of your code. What are you trying to do? Finally, you should never run queries in loops. Quote Link to comment https://forums.phpfreaks.com/topic/273750-helpundefined-variable-when-saving-session-data-to-db/#findComment-1408797 Share on other sites More sharing options...
Diether Posted January 28, 2013 Author Share Posted January 28, 2013 pls help me to fix my codes, it took me two hours already and i can't move on Quote Link to comment https://forums.phpfreaks.com/topic/273750-helpundefined-variable-when-saving-session-data-to-db/#findComment-1408799 Share on other sites More sharing options...
shlumph Posted January 28, 2013 Share Posted January 28, 2013 Assuming that the session data is set, you are assigning those variables incorrectly. I believe you meant this: $itemId = $_SESSION["cart_array"]["item_id"]; $qty = $_SESSION["cart_array"]["quantity"]; Also, in your query, $itemid should be $itemId, as variable names are case sensitive. Hopefully this gets you on the right track. And don't forget to include session_start(); at the beginning of your scripts that are making use of sessions. Quote Link to comment https://forums.phpfreaks.com/topic/273750-helpundefined-variable-when-saving-session-data-to-db/#findComment-1408801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.