0

我在页面上有一个表单,该表单将记录 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'];
    }
    }
4

3 回答 3

0

您还没有将 php 标签<?php ?>放在 html 中

<input type="hidden" name="sel_record" value="<?php echo $id; ?>">
于 2013-06-05T19:39:53.190 回答
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'];
  }
}

不是一个完整的例子,但你明白了。

于 2013-06-05T19:45:14.040 回答
0

您必须转义字符串...并且可以将单引号放在 order 和 id 周围。

尝试:

$result = mysql_query("SELECT * FROM order WHERE id = '" . $sel_record . "'")

如果 $sel_record 是一个字符串,否则删除单引号:

...WHERE id = " . $sel_record)

您还可以使用函数 sprintf 和 mysql_real_escape_string 来格式化:

$query = sprintf("SELECT * FROM order WHERE id = '%s'", mysql_real_escape_string($sel_record));

于 2013-06-05T20:01:02.290 回答