我在页面上有一个表单,它将记录ID发布到我想要显示该记录的页面上。表格是:
<form method="post" action="update.php">
<input type="hidden" name="sel_record" value="$id">
<input type="submit" name="update" value="Update this Order">
</form>
我已经测试过看看$ id是否获得了正确的值,而且确实如此。当它发布到update.php时,它不会返回任何值。有任何想法吗?这是更新页面代码:
$sel_record = $_POST['sel_record'];
$result = mysql_query("SELECT * FROM `order` WHERE `id` = '$sel_record'") or die (mysql_error());
if (!$result) {
print "Something has gone wrong!";
} else {
while ($record = mysql_fetch_array($result)) {
$id = $record['id'];
$firstName = $record['firstName'];
$lastName = $record['lastName'];
$division = $record['division'];
$phone = $record['phone'];
$email = $record['email'];
$itemType = $record['itemType'];
$job = $record['jobDescription'];
$uploads = $record['file'];
$dateNeeded = $record['dateNeeded'];
$quantity = $record['quantity'];
$orderNumber = $record['orderNumber'];
}
}
答案 0 :(得分:0)
你没有把php标签<?php ?>
放在html
<input type="hidden" name="sel_record" value="<?php echo $id; ?>">
答案 1 :(得分:0)
您还应该尝试在while循环之外定义这些变量。
$id = '';
$result = mysql_query("SELECT * FROM `order` WHERE `id` = '$sel_record'") or die (mysql_error());
if (!$result) {
print "Something has gone wrong!";
} else {
while ($record = mysql_fetch_array($result)) {
$id = $record['id'];
}
}
不是一个完整的例子,但你明白了。
答案 2 :(得分:0)
你必须转义字符串......你可以在订单和id周围删除单引号。
尝试:
$ result = mysql_query(“SELECT * FROM order WHERE id ='”。$ sel_record。“'”)
如果$ sel_record是一个String,否则删除单引号:
... WHERE id =“。$ sel_record)
您还可以使用函数sprintf和mysql_real_escape_string进行格式化:
$ query = sprintf(“SELECT * FROM order WHERE id ='%s'”, mysql_real_escape_string($ sel_record));