0

我收到此代码未定义的索引错误:

// Select all bookings
$sql = "SELECT * FROM booking";

$result = mysqli_query($con,$sql);

echo "<p>";

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    // echo $row['custName'] . " - " . $row['roomNb'] . " - " . $row['date'];
    echo $row['custName'];
}

错误:

Notice: Undefined index: custName in C:\xampp\htdocs\alxbook\index.php on line 40

我正在从我的表中选择所有列。我对 $row['roomNb'] 和 $row['date'] 没有问题,但由于某种原因 $row['custName'] 给我带来了问题。custName 的拼写正确。

这可能是什么原因造成的?

4

1 回答 1

2

将一段调试代码放入您的脚本中以证明名称正确:-

// Select all bookings
$sql = "SELECT * FROM booking";

$result = mysqli_query($con,$sql);

echo "<p>";

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

    print_r( $row );  // debug code

    // echo $row['custName'] . " - " . $row['roomNb'] . " - " . $row['date'];
    echo $row['custName'];
}
于 2013-08-28T12:43:37.240 回答