Jump to content

numRows


westman

Recommended Posts

My code is not working, here it is...

$stmt = $conn->prepare("SELECT id FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$numRows = $stmt->num_rows;
$stmt->close();
if($numRows > 0) {	
$error = "Your Email is already in use. Please try another.";
$conn->close();
}else{
// all good
$conn->close();
}

any help?

Link to comment
Share on other sites

You need to add some debugging statements. You have to try to find out what your code is doing and why it's not working properly.

// Are we getting the correct e-mail address?
var_dump($email);

$stmt = $conn->prepare("SELECT id FROM users WHERE email = ?");
if(!$stmt) {
  // Was the query valid SQL?
  echo 'SQL error: ' . $stmt->error . '<br>';
}

$stmt->bind_param("s", $email);
$success = $stmt->execute();
if(!$success) {
  // Did the query execute properly?
  echo 'MySQL error: ' . $conn->error . '<br>';
}

$numRows = $stmt->num_rows;

// Is this a number or is it null?
var_dump($numRows);


$stmt->close();
if($numRows > 0) {	
$error = "Your Email is already in use. Please try another.";
$conn->close();
}else{
// all good
$conn->close();
}

 

Link to comment
Share on other sites

From the manual:

The use of mysqli_stmt_num_rows() depends on whether or not you used mysqli_stmt_store_result() to buffer the entire result set in the statement handle.

The examples in the manual do show using store_result first.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...