0

Please guys I need you help on updating mysql database. Below is the code:

$sql_1 = "UPDATE tbl_courier
          SET status = '$status', 
              comments = '$comments', 
              aarrival = '$aarrival', 
              transferdate = '$transferdate', 
              bl = '$bl', 
              `containerno` = '$containerno', 
              eta = '$eta', 
              rev_name = '$Receivername'
           WHERE cid = $cid
              AND cons_no = '$cons_no'";

  dbQuery($sql_1);

Every column updates with the new input except containerno, eta and rev_name

What have i done wrong please help...

7
  • Can you confirm $containerno, $eta and $rev_name have appropriate values? Echo them out, or echo out the whole query. Commented May 28, 2014 at 22:17
  • You should probably be using a prepared statement. It will really cut back on 1) errors like this and 2) SQL injection opportunities. Commented May 28, 2014 at 22:25
  • Add error reporting to the top of your file(s) error_reporting(E_ALL); ini_set('display_errors', 1); if you're not already doing so. Commented May 28, 2014 at 22:30
  • I'm questioning the spelling of aarrival are you sure that column isn't named arrival? Plus, make sure the cid column is an int type. Also, GigaWatt mentioned in the now-deleted answer, about removing the backticks around the containerno. You should also make sure that your elements are indeed named with no typos, if this is coming from a form. You'll need to show a bit more code. As it stands, your question is unclear. Commented May 28, 2014 at 22:31
  • Notice: Undefined index: $containerno in /home/masglobl/public_html/track/process.php on line 135 Notice: Undefined index: $eta in /home/masglobl/public_html/track/process.php on line 136 Notice: Undefined index: $Receivername in /home/masglobl/public_html/track/process.php on line 137 Notice: Undefined variable: Containerno in /home/masglobl/public_html/track/process.php on line 142 Warning: Cannot modify header information - headers already sent by (output started at /home/masglobl/public_html/track/process.php:135) in /home/masglobl/public_html/track/process.php on line 146 Commented May 28, 2014 at 22:44

1 Answer 1

1

As far as I can see, there is one line out of place. Change this:

$sql_1 = "UPDATE tbl_courier
          SET status = '$status', 
              comments = '$comments', 
              aarrival = '$aarrival', 
              transferdate = '$transferdate', 
              bl = '$bl', 
              `containerno` = '$containerno', 
              eta = '$eta', 
              rev_name = '$Receivername'
           WHERE cid = $cid
              AND cons_no = '$cons_no'";

  dbQuery($sql_1);

To this:

$sql_1 = "UPDATE tbl_courier
          SET status = '$status', 
              comments = '$comments', 
              aarrival = '$aarrival', 
              transferdate = '$transferdate', 
              bl = '$bl', 
              containerno = '$containerno', 
              eta = '$eta', 
              rev_name = '$Receivername'
           WHERE cid = $cid
              AND cons_no = '$cons_no'";

  dbQuery($sql_1);

It's this line here:

`containerno` = '$containerno',

I believe you do not need the tilda before and after the column.

Old line:

`containerno` = '$containerno',

New line:

containerno = '$containerno',

When you add the tildas, as you can see. It is causing the rest of the syntax to nullify.

Sign up to request clarification or add additional context in comments.

1 Comment

The error_reporting(E_ALL); ini_set('display_errors', 1); that Fre-ii gave was very helpful. I saw that my code was $containerno = $_POST['$containerno']; instead of $containerno = $_POST['containerno'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.