我通过 url 从 android 向 php 发送 2 个数组列表。Mysql 包含包含两列 menuimage、menuname 的测试表。我只想更新菜单名称,但它只更新 mysql 数据库中菜单名称的第一行
到目前为止尝试过-
<?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";
}
?>