-3

lately i'm working with php i want to display data but nothing shown here my code, i want to get data from data base and show it but nothing is shown

    <?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();

?>
Badr Kouki
  • 11
  • 2
  • 5
  • 1
    **Stop** using deprecated `mysql_*` API. Use `mysqi_* or `PDO`. Also learn about prepared statements to prevent SQL injection – Jens Jun 10 '18 at 13:28
  • 1
    Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Jens Jun 10 '18 at 13:31
  • 1
    remove the single quotes arround the column name. Hint `mysql_error` shows you the syntax errors – Jens Jun 10 '18 at 13:32

1 Answers1

0

Use the following code which uses mysqli_*. what you are using has been deprecated long back.

<?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);?>
Suraj Rana
  • 70
  • 13