I am sending 2 arraylist from android to php through url .
Mysql contains test table with two columns menuimage, menuname. I want to update menu name only but it is updating only first row of menuname in mysql database
Tried so far-
<?php
$old_menu_names=explode(',',preg_replace('/^.*\[(.*)\].*$/','$1',trim($_POST['menuname'], '[]')));
$new_menu_names=explode(',',preg_replace('/^.*\[(.*)\].*$/','$1',trim($_POST['editmainmenu'], '[]')));
mysql_connect("localhost", "root", "MobixMySQL");
mysql_select_db("cozydine");
foreach ($old_menu_names as $key => $old_name) {
$new_name = mysql_real_escape_string($new_menu_names[$key]);
$old_name = mysql_real_escape_string($old_menu_names[$key]);
echo $new_name;
mysql_query("UPDATE `mainmenu` SET `menuname` = '$new_name' WHERE menuname = '$old_name'")
or die('Error' . mysql_error());
echo "Updated";
}
?>
Thats because their in only one old name in the db that is now replaced with new name. if you want to update all the values of rows with new do something like this
EDITED
in your loop instead of using key for new name use a counter
}
Because key might not be working for new names array.