monkeybidz Posted October 16, 2007 Share Posted October 16, 2007 Can someone verify this code. It is to insert data to database if $msg not true. It is connecting to database, but not inserting data. if(!$msg){ $user_id=$_REQUEST['id']; $freight_status=$_POST['freight_status']; $pod=$_POST['pod']; $amount_due=$_POST['amount_due']; $due_date=$_POST['due_date']; $date_paid=$_POST['date_paid']; $job_number=$_POST['job_number']; $pic_date=$_POST['pic_date']; $del_date=$_POST['del_date']; $pic_city=$_POST['pic_city']; $del_city=$_POST['del_city']; $pic_time=$_POST['pic_time']; $del_time=$_POST['del_time']; $insert=mysql_query("INSERT INTO `jobs` (id_num, user_id, freight_status, pod, amount_due, due_date, date_paid, job_number, pic_date, del_date, pic_city, del_city, pic_time, del_time)VALUES('','$user_id','$freight_status','$pod', '$amount_due','$due_date', $date_paid,'$job_number', '$pic_date', '$del_date', '$pic_city', '$del_city', '$pic_time', '$del_time')"); $msg="Job was inserted to user account."; }else{ $msg="Job was not inserted to database."; } } Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/ Share on other sites More sharing options...
jd2007 Posted October 16, 2007 Share Posted October 16, 2007 remove the quotes here : `jobs` Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-370388 Share on other sites More sharing options...
monkeybidz Posted October 16, 2007 Author Share Posted October 16, 2007 $date_paid had no quotes in VALUES line. I still only get id and user_id inserted only. Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-370389 Share on other sites More sharing options...
monkeybidz Posted October 16, 2007 Author Share Posted October 16, 2007 `` removed, still no dice. Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-370392 Share on other sites More sharing options...
monkeybidz Posted October 16, 2007 Author Share Posted October 16, 2007 table field " freight_status" is not set correctly. I use a drop down menu in the form. What should i use for: type, Length/Values, NULL and so on in database? Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-370415 Share on other sites More sharing options...
ryeman98 Posted October 16, 2007 Share Posted October 16, 2007 I think I noticed your problem. If id_num is set to auto_increment, you don't need it in the query Replace this: $insert=mysql_query("INSERT INTO `jobs` (id_num, user_id, freight_status, pod, amount_due, due_date, date_paid, job_number, pic_date, del_date, pic_city, del_city, pic_time, del_time)VALUES('','$user_id','$freight_status','$pod', '$amount_due','$due_date', $date_paid,'$job_number', '$pic_date', '$del_date', '$pic_city', '$del_city', '$pic_time', '$del_time')"); to this: $insert=mysql_query("INSERT INTO `jobs` (user_id, freight_status, pod, amount_due, due_date, date_paid, job_number, pic_date, del_date, pic_city, del_city, pic_time, del_time) VALUES("'$user_id','$freight_status','$pod', '$amount_due','$due_date', $date_paid,'$job_number', '$pic_date', '$del_date', '$pic_city', '$del_city', '$pic_time', '$del_time')"); I also noticed that you ended the VALUES with double quotes " but didn't begin with double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-370420 Share on other sites More sharing options...
monkeybidz Posted October 16, 2007 Author Share Posted October 16, 2007 Did not work. Those are single quotes, they just look close together here. Those need to look like this (' ', '$user_id', in order to create an auto id number in id_num. Those are fine, it is just everything after that that is not posting in database. Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-370424 Share on other sites More sharing options...
fenway Posted October 17, 2007 Share Posted October 17, 2007 Echo the interpolated query. Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-371535 Share on other sites More sharing options...
monkeybidz Posted October 17, 2007 Author Share Posted October 17, 2007 Well, i got it to insert the fields now by removing $user_id=$_REQUEST['id']; $_REQUEST['id'] is already defined as $id further up the page. Problem now is it inserts random extra rows. sometimes 1 row correctly, and sometime up to 6 rows with different id_num, but same user_id. Any clues? if($id){ $insert=mysql_query("INSERT INTO jobs (id_num, user_id, freight_status) VALUES (' ','$id','$freight_status')"); $msg="Job was inserted to user account."; }else{ $msg="Job was not inserted to database."; } } Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-371626 Share on other sites More sharing options...
monkeybidz Posted October 17, 2007 Author Share Posted October 17, 2007 It worked fine the way i posted above. The reason for the extra rows was when iI refresh my browser and hit RETRY button. It was sending empty fields. I have now defined error messages to prevent this from happening: Example: if(empty($user_id)){ $msg[]="No user ID was selected"; $insert=""; } if(empty($freight_status)){ $msg[]="Please enter freight status information."; $insert=""; }else{ $insert=mysql_query("INSERT INTO jobs (id_num, user_id, freight_status) VALUES (' ', '$id', '$freight_status')"); } } Quote Link to comment https://forums.phpfreaks.com/topic/73419-solved-need-verification/#findComment-371814 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.