I am trying to run a SELECT * FROM <table> WHERE <param> = <value> LIMIT 1
SQL query with MySQLi
I have built this code snippet, which works perfect if the input id is present in SQL DB.
$id = $_GET['id'];
// preparing and binding
$stmt = $conn->prepare("SELECT * FROM `testtable1` WHERE `userid` = ? LIMIT 1");
$stmt->bind_param("i", $id);
// setting parameters and execute
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
echo $row['email'] . '<br><br>';
What I want to know is, how would I know if the input id (which was passed along with the URL) is NOT present in the DB? Currently, If the ID's present in the DB, the email
param's value shows up. But if it's not present, nothing shows up..
So with the above piece of code, how do check whether the input ID is correct or not - so if incorrect I could show an 'Incorrect ID' message there?