Jump to content

[SOLVED] Need Verification


monkeybidz

Recommended Posts

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.";
}
}

Link to comment
https://forums.phpfreaks.com/topic/73419-solved-need-verification/
Share on other sites

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.

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.";
}
}

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')");

  }

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.