PHP不会显示来自数据库mysql的任何数据

时间:2018-06-10 13:23:13

标签: php mysql

最近我正在使用php我想显示数据,但这里没有显示我的代码,我想从数据库中获取数据并显示它但没有显示

    <?php 
$name = $_POST["names"] ;
$servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "phpapp";

        // Create connection
        $conn = mysql_connect("localhost", "root", "");
        $db = mysql_select_db($dbname, $conn);
        // Check connection
        echo "Connected successfully";

        $query = mysql_query("SELECT * FROM `user` WHERE 'name'='$name' " , $conn) or die ('Erreur SQL ! <br />'.mysql_error());
        $row = mysql_fetch_array($query) ;
        while($row = mysql_fetch_array($query)){
            echo "<table>";
            echo "<tr>";
            echo "<td>".$row['name']."</td>";
            echo "<td>".$row['lastname']."</td>";
            echo "<td>".$row['email']."</td>";
            echo "</tr>";
            echo "</table>";
        }
        mysql_close();

?>

1 个答案:

答案 0 :(得分:0)

使用以下使用mysqli_ *的代码。你正在使用的东西早已被弃用。

<?php 
$name = $_POST["names"] ;
$servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "phpapp";

    // Create connection
$conn=mysqli_connect($servername ,$username,$password,$dbname);

if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result =mysqli_query($con, "SELECT * FROM `user` WHERE `name` = '$name'");
while ($row = mysqli_fetch_array($result)){
        echo "<table>";
        echo "<tr>";
        echo "<td>".$row['name']."</td>";
        echo "<td>".$row['lastname']."</td>";
        echo "<td>".$row['email']."</td>";
        echo "</tr>";
        echo "</table>";
    }
mysqli_close($conn);?>