I have a problem updating record on a table. Below is the detail:
I have a table named tbl_option, it has 2 field : option_name, option_value. The current table record is follow:
option_name | option_value
site_name | MySite
site_desc | About anything
I want to update both site_name and site_desc option_value, here is my php script to update the site_name and site_desc option_value:
require "include/config.php";
$name = "MyNewSitess";
$desc = "About Computer";
$query = mysql_query("UPDATE tbl_option SET option_value='$name' WHEREoption_name='site_name';# UPDATE tbl_option SET option_value='$desc' WHERE option_name='site_desc'");
if ($query) { echo "Saved"; }
else echo "Not saved : ".mysql_errno()." | ".mysql_error();
after executed I get the following error:
Not saved : 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE tbl_option SET option_value='About Computer' WHERE option_name='site_desc' at line 1
The record not updatd. But when I add (#) before the second UPDATE query :
<?php
...
$query = mysql_query("UPDATE tbl_option SET option_value='$name' WHERE option_name='site_name'; #UPDATE tbl_option SET option_value='$desc' WHERE option_name='site_desc'");
...
?>
It not showing any error. I get the following :
Saved
and the record is updated
What is the problem ?
Yes, I imitate the wordpress table concept but I don't know how to do the UPDATE query to the table.
mysql_query()on php.net (that should be your first stop whenever you run into problems or first start learning about a function). It clearly states that you can only make a single query at a time. If you look at how the mysql_* functions work, you'll see why that is. Lastly, the mysql extension is deprecated. Use mysqli or pdo instead. Again, all of this info is obvious if you read the manual.mysql_query()doesn't support multiple queries. It's right in the description for mysql_query.