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.
Change from
to
However, if this is a WordPress update, then you are better off posting this question here. You might just get a better solution 🙂
Another option if you are doing this only once is to directly the console or a popular tool by the name of of PhpMyAdmin to do the updates.