我使用此代码获得了未定义的索引错误:
// 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的拼写是正确的。
可能导致这种情况的原因是什么?
答案 0 :(得分: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'];
}