下面的更新表格会根据问卷的一些预定义答案更新密码保护区域中每个用户的食物偏好数据。
例如,
问:你最喜欢吃什么?
回答:
- 奶酪
- 肉
- 沙拉
用户提交时,应根据变量的预定义值永久禁用以下表单的提交按钮$trigger
。
$trigger = '1';
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formX")) {
$updateSQL = sprintf("UPDATE foodtable SET food_preference=%s, trigger=%s, WHERE food_id=%s",
GetSQLValueString($_POST['food_preference'], "text"),
GetSQLValueString(trim($trigger), "int"),
GetSQLValueString($_POST['food_id'], "int"));
mysql_select_db($database_XYZ, $XYZ);
$Result1 = mysql_query($updateSQL, $XYZ) or die(mysql_error());
$updateGoTo = "preference.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="trigger" value="<?php echo "$trigger"; ?>" />
</td>
<td>
<input type="submit" value="Update Food Name" />
</td>
</tr>
</table>
</form>
如何使用纯 php 条件语句执行它?我也应该改变html表单代码吗?任何参考或建议将不胜感激。
编辑
以下更新表格在受密码保护的用户区域更新个人用户的食物偏好。
$trigger = '1';
//note: default value of $trigger= '0'; when user submits data using insert form primarily. when they update data using this update form the value changes to `1`
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formX")) {
$updateSQL = sprintf("UPDATE foodtable SET food_name=%s, trigger=%s WHERE food_id=%s",
GetSQLValueString($_POST['food_name'], "text"),
GetSQLValueString(trim($trigger), "int"),
GetSQLValueString($_POST['food_id'], "int"));
mysql_select_db($database_XYZ, $XYZ);
$Result1 = mysql_query($updateSQL, $XYZ) or die(mysql_error());
$updateGoTo = "preference.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']; ?>" />
<input type="hidden" name="trigger" value="<?php echo "$trigger"; ?>" />
</td>
<td>
< ?php
$disabled = "disabled";
if (isset (which conditional statement shall disable the form permanently based on $trigger = '1'; ?)) {
echo "<input type='submit' value='Update Food Name' " . $disabled . "/>";
}else{
echo "<input type='submit' value='Update Food Name'/>";
}
?>
</td>
</tr>
</table>
</form>
顺便说一句,我使用以下 mysql 语法来获取禁用提交按钮的列值:
$query = "SELECT food_id, food_name, trigger FROM foodtable WHERE food_id > 0 AND trigger = '1'";
我应该使用哪个条件 php 语句来禁用此已编辑帖子中指示的 html 部分的表单?
它可以以很长的方式解决,但我期待一个合理的方法。
如果您觉得我的问题让您足够清楚,您的回复将不胜感激。