PHP,MySQL:无法解释此未定义的索引错误 [英] PHP, MySQL: can't explain this undefined index error

查看:76
本文介绍了PHP,MySQL:无法解释此未定义的索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码出现未定义的索引错误:

I'm getting an undefined index error with this code:

// 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的拼写正确.

I'm selecting all columns from my table. I have no problem with $row['roomNb'] and $row['date'] but for some reason $row['custName'] is giving me problems. The spelling of custName is correct.

可能是什么原因造成的?

What could be causing this?

推荐答案

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

Put a piece of debug code into your script to proove that the name is correct:-

// 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'];
}

这篇关于PHP,MySQL:无法解释此未定义的索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆