Php 如何在空表数据中显示NULL或N/A

Php 如何在空表数据中显示NULL或N/A,php,mysql,Php,Mysql,phpMyAdmin中的空格似乎打印出了我的php文件中关闭表数据标记的一部分。我想把空格留空,或者用N/A之类的东西来表示它是空的 这是我的php文件中的我的名字 这是我在phpMyAdmin的照片 这是导致问题的文件 <?php mysql_connect('localhost','root',''); mysql_select_db('project'); if (isset($_POST['update'])){ $UpdateQuery

phpMyAdmin中的空格似乎打印出了我的php文件中关闭表数据标记的一部分。我想把空格留空,或者用N/A之类的东西来表示它是空的

这是我的php文件中的我的名字

这是我在phpMyAdmin的照片

这是导致问题的文件

<?php

    mysql_connect('localhost','root','');
    mysql_select_db('project');

    if (isset($_POST['update'])){
        $UpdateQuery = "UPDATE users SET id='$_POST[id]', username='$_POST[username]', password='$_POST[password]', first_name='$_POST[first_name]', last_name='$_POST[last_name]', email='$_POST[email]'
                        WHERE id='$_POST[hidden]'";
                        mysql_query($UpdateQuery, mysql_connect('localhost','root',''));    
    };

    if (isset($_POST['delete'])){
        $DeleteQuery = "DELETE FROM users WHERE id='$_POST[hidden]'";
                        mysql_query($DeleteQuery, mysql_connect('localhost','root',''));    
    };

    if (isset($_POST['add'])){
        $AddQuery = "INSERT INTO users (id, username) VALUES ('$_POST[uid]','$_POST[uusername]','$_POST[upassword]','$_POST[ufirst_name]','$_POST[ulast_name]','$_POST[uemail]')";
                        mysql_query($AddQuery, mysql_connect('localhost','root',''));   
    };

    $sql = "SELECT * FROM users";
    $records = mysql_query($sql);   

    //session_start();
    //if(!isset($_SESSION["id"])){
    //  header("location:main.html");
    //} else {
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Table Display (Allows instructor to add students, delete, and update id and names)
    </title>
    <link rel="stylesheet" href="main.css">
</head>
<body>

    <table width="25%" border="1" cellpadding="1" cellspacing="1" align="center">
        <tr>
            <th>ID</th>
            <th>Username</th>
            <th>Password</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Email</th>
            <th></th>
            <th></th>
            <th></th>
        </tr>

        <?php
            while ($users = mysql_fetch_assoc($records)) {
                echo "<form action=displayusers.php method=post>";
                echo "<tr>";

                echo "<td>"."<input type=text name=id value=".$users['id']." </td>";
                echo "<td>"."<input type=text name=username value=".$users['username']." </td>";
                echo "<td>"."<input type=text name=password value=".$users['password']." </td>";
                echo "<td>"."<input type=text name=first_name value=".$users['first_name']." </td>";
                echo "<td>"."<input type=text name=last_name value=".$users['last_name']." </td>";
                echo "<td>"."<input type=text name=email value=".$users['email']." </td>";
                echo "<td>"."<input type=hidden name=hidden value=".$users['id']." </td>";
                echo "<td>"."<input type=submit name=update value=Update"." </td>";
                echo "<td>"."<input type=submit name=delete value=Delete"." </td>";


                echo "</tr>";
                echo "</form>";
            }//end while
            echo "<form action=displayusers.php method=post>";
            echo "<tr>";
            echo "<td><input type=text name=uid></td>";
            echo "<td><input type=text name=uusername></td>";
            echo "<td><input type=text name=upassword></td>";
            echo "<td><input type=text name=ufirst_name></td>";
            echo "<td><input type=text name=ulast_name></td>";
            echo "<td><input type=text name=uemail></td>";
            echo "<td>"."<input type=submit name=add value=Add"." </td>";
            echo "<td>";
            echo "<td>";

            echo "</form>";

        ?>

    </table>

</body>
</html>

<?php
//} // end else statement
?>

停止使用已弃用且自PHP7起已删除的mysql_*函数。迁移到PDO并开始使用准备好的语句。您正在编写无效的(X)HTML。您需要将每个属性值写入引号中,并关闭
input
元素<代码>
或使用mysqli。。为了进一步添加到这些家伙,在您的循环中,您可以将结果添加到变量中,让它检查它们是否为空/空,然后将其更改为您想要的任何内容。这样,如果它是空的/空的,你可以让它显示N/A或任何你想要的。顺便说一句,最好不要把你学生的电子邮件/密码等。。在线程上。;)假设他们是真人。另外,
如果($users['username']=='ServerAdmin')继续将其放在循环的顶部,即使您更改其ID号,它也会跳过ServerAdmin。或者您可以将其添加到查询、
和用户名!='ServerAdmin'
谢谢,工作非常好!我正在努力切换到mysqli,我刚刚得到了很多代码,这些代码会导致一些文件中出现错误。