0

Trying to execute SQL query like below in my PHP. It works fine when executed on database.

UPDATE `wp_essx95_cf7dbplugin_submits` SET field_value = 'hiya' WHERE submit_time = '1500944028.4748' and field_name='status'

In my PHP I have two values stored as variable. I'm calling it like this:

$SQL = "UPDATE `wp_essx95_cf7dbplugin_submits` SET field_value = '$status' WHERE submit_time = '$trade_num' and field_name='status'";
$result = mysqli_query($db_handle, $SQL);
return $result;

However it doesn't seem to be working.

Am I writing the statement correctly? How can I further debug the situation, like see the result of the PHP query. I have the PHP function return $result, and echo it on my page, but it doesn't seem to output anything.

echo(setStatus($time, $sts));

Thanks

2 Answers 2

2

Try escaping the variables and adding a die statement if an error occurs. Also do not forget to clean the data to prevent mysql injection.

$SQL = "UPDATE `wp_essx95_cf7dbplugin_submits` SET field_value = '".$status."' WHERE submit_time = '".$trade_num."' and field_name='status'";
$result = mysqli_query($db_handle, $SQL) or die(mysqli_error($db_handle));
return $result;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, The die statement came in handy! I had connected to the SQL server, but didn't select a database yet.
0

Try what @Kevin P says.... I looks like works ;)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.