语法
$default_message = "No food name entered";
if(isset($_POST['food_name']) && !empty($_POST['food_name'])){
echo $_POST['$dafult_message'];
}
应该检查数据库中的字段food_name
是否为空或为空,并在以下表单使用空字段更新时尝试将预定义的值No food name entered
插入数据库,但不幸的是它不会更新预定义的值。我看不出有什么不合逻辑的地方。任何想法?
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formX")) {
$default_message = "No food name entered";
if(isset($_POST['food_name']) && !empty($_POST['food_name'])){
echo $_POST['$dafult_message'];
}
$updateSQL = sprintf("UPDATE foodtable SET food_name=%s WHERE food_id=%s",
GetSQLValueString($_POST['food_name'], "text"),
GetSQLValueString($_POST['food_id'], "int"));
mysql_select_db($database_XYZ, $XYZ);
$Result1 = mysql_query($updateSQL, $XYZ) or die(mysql_error());
$updateGoTo = "choicefood.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
exit ();
}
<form action="<?php echo $editFormAction; ?>" method="post" name="formX" id="formX">
<table align="center">
<tr valign="baseline">
<td align="right" nowrap="nowrap">Update Food Name:</td>
<td><input type="text" name="food_name" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">
<input type="hidden" name="MM_update" value="formX" />
<input type="hidden" name="food_id" value="<?php echo $query['food_id']; ?>" />
</td>
<td>
<input type="submit" value="Update Food Name" />
</td>
</tr>
</table>
</form>
谢谢,