I am trying to change my code to msqli prepared statements from mysql. I am not sure how to adapt my code that currently works to check if there is an email already in the d
Should be something like this:
// enable error reporting for mysqli
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// create mysqli object
$mysqli = new mysqli(/* fill in your connection info here */);
$email = $_POST['email']; // might want to validate and sanitize this first before passing to database...
// set query
$query = "SELECT COUNT(*) FROM users WHERE email = ?";
// prepare the query, bind the variable and execute
$stmt = $mysqli->prepare($query);
$stmt->bind_param('s', $email);
$stmt->execute();
// grab the result
$stmt->bind_result($numRows);
$stmt->fetch();
if ($numRows) {
echo "<p class='red'>Email is already registered with us</p>";
} else {
// ....
}
This link may help you as well:
http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php