我想同时将两个字段更新到表中,但它不起作用 任何人都可以帮助我
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf(
"UPDATE child,list SET child.list_num = list.list_id WHERE child.user_id = list.user_id",
GetSQLValueString($_POST['list_num'], "int"),
GetSQLValueString($_POST['id'], "int")
);
mysql_select_db($database_amar, $amar);
$Result1 = mysql_query($updateSQL, $amar) or die(mysql_error());
$updateGoTo = "list_child.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_edit = "-1";
if (isset($_GET['id'])) {
$colname_edit = $_GET['id'];
}
mysql_select_db($database_amar, $amar);
$query_edit = sprintf(
"SELECT * FROM child, list WHERE id= %s",
GetSQLValueString($colname_edit, "int")
);
$edit = mysql_query($query_edit, $amar) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
$totalRows_edit = mysql_num_rows($edit);
答案 0 :(得分:0)
我已经尝试过您的查询,并且其工作完美无缺
"UPDATE child,list SET child.list_num = list.list_id WHERE child.user_id = list.user_id"
但是我对你的实现有疑问,为什么你在这里使用sprintf?
$updateSQL = sprintf("UPDATE child,list SET child.list_num = list.list_id WHERE child.user_id = list.user_id ",
GetSQLValueString($_POST['list_num'], "int"),
GetSQLValueString($_POST['id'], "int"));
它表明您的要求与您的实施略有不同。您要么在查询中缺少某些要使用参数的地方
GetSQLValueString($_POST['list_num'], "int") and GetSQLValueString($_POST['id'], "int").
目前您的查询将更新表而不进行任何检查,但它不符合sprintf的要求。尝试
$query_edit = sprintf("SELECT * FROM child, list WHERE id= %s", GetSQLValueString($colname_edit, "int"));