I can fetch data from phpmyadmin db where id = 2.but i can not fetch value where id = 2

this is my sql query

$sql = “SELECT * FROM employees”;

This is my db input from php page

id name email
phoneno address Delete 1 Ajit Nandi nandi@gmail.com 123456789 kolkata Delete 2 Amit Das das@gmail.com 987654321 salt lake

 

Default Asked on December 17, 2019 in PHP.
Add Comment
1 Answer(s)

Select Query:

$link = mysqli_connect("localhost", "root", "", "DBNAME");  
if ($link == = false) {
    die("ERROR: Could not connect. "
                .mysqli_connect_error());}
  
$sql = "SELECT * FROM employees WHERE id=2";
if ($res = mysqli_query($link, $sql)) {
    if (mysqli_num_rows($res) > 0) {
        echo "<table>";
        echo "<tr>";
        echo "<th>Name</th>";
        echo "<th>Email</th>";
        echo "<th>Phone No</th>";
        echo "</tr>";
        while ($row = mysqli_fetch_array($res)) {
            echo "<tr>";
            echo "<td>".$row['name']."</td>";
            echo "<td>".$row['email']."</td>";
            echo "<td>".$row['phoneno']."</td>";
            echo "</tr>";        }
        echo "</table>";
        mysqli_free_res($res);
    }
    else {
        echo "No matching records are found."; }
}
else {
    echo "ERROR: Could not able to execute $sql. ".mysqli_error($link);
}
mysqli_close($link);

Delete Query:

$sql = "DELETE FROM employees WHERE id=2";
if(mysqli_query($link, $sql)){
    echo "Record was deleted successfully.";
} 
else{
    echo "ERROR: Could not able to execute $sql. ". mysqli_error($link);
}
IT Head Answered on December 17, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.