I have 2 arrays, $arr for the old menu name, and $arr1 for the new menu name. I want to replace the old menu name with the new in my database. I have the following code but it throws out an error.
<?php
$arr = explode(',', preg_replace('/^.*\[(.*)\].*$/', '$1', trim($_POST['menuname'],
'[]')));
$arr1 = explode(',', preg_replace('/^.*\
[(.*)\].*$/', '$1', trim($_POST['editmainmenu'], '[]')));
mysql_connect("localhost", "root", "root");
mysql_select_db("test");
foreach ($arr as $key => $value)
{
$value1 = $arr1[$key];
mysql_query("update test set (menuname) =('" .
mysql_real_escape_string($value1) . "') where menuname=('" .
mysql_real_escape_string($value) . "')")or
die('unable' . mysql_error());
echo "updated";
}
?>
I get the following error:
04-09 19:06:27.201: I/System.out(1291): unableYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(menuname) =('') where menuname=('Food Menu')' at line 1
Please tell me how to solve this issue. Thanks!
This is what your code looks like after the cleanup I did to it:
##What I did:
$arror$arr1, in larger applications, you’ll be lost in no time.In short, I suggest you read a good book about best practices and programming concepts.