错误:注意:使用未定义的常量

时间:2017-07-10 03:34:14

标签: php html mysql undefined

我是php的新手,我的代码一直在抛出一个错误,上面写着

  

"注意:使用未定义的常量client_id first_name last_name   假设' client_id' '如first_name' '姓氏'在....."

这就是我的代码的样子。

 $DBConnect = @mysqli_connect('localhost', 'root', '', 'client_names');
if($DBConnect === FALSE){
    die("Connection failed:" . $DBConnect->connect_error);
}

$DBName = "client_names";
if (!@mysqli_select_db($DBConnect, $DBName)){
    echo "<p>Cannot open the database!</p>";
}
else{

    $TableName ="client_info";
    $SQLstring = "Select client_id, first_name, last_name FROM $TableName";
    $QueryResult = @mysqli_query($DBConnect, $SQLstring);
    if(mysqli_num_rows($QueryResult)==0){
        echo "<p>There are no client information!</p>";
    }
    else {
        echo "<p> List of Clients</p>";
        echo "<table width='100%'border='1'>";
        echo "<tr><th>Client number<tr><th>First Name<tr><th>Last Name";
        while($Row = mysqli_fetch_assoc($QueryResult)){
            echo "<tr><td>{$Row[client_id]}</td>";
            echo "<td>{$Row[first_name]}</td>";
            echo "<td>{$Row[last_name]}</td>"</tr>";

假设从我的数据库中提取数据并将其显示在表格上。你能帮忙的话,我会很高兴。谢谢。

1 个答案:

答案 0 :(得分:0)

像client_id这样的任何字符串索引都是一个字符串,所以请尝试使用单引号。

echo "<tr><td>{$Row['client_id']}</td>";
echo "<td>{$Row['first_name']}</td>";
echo "<td>{$Row['last_name']}</td>"</tr>";

没有引号 - PHP会假设您指的是一个常量,如错误消息所示。

并在你的函数调用中松开那些@。像这样掩盖错误是一个非常糟糕的主意。你只使用那些,如果你真的非常非常罕见......

相关问题