westman Posted February 4, 2018 Share Posted February 4, 2018 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 More sharing options...
Ingolme Posted February 4, 2018 Share Posted February 4, 2018 What does "not working" mean? Are you getting any error messages? Link to comment Share on other sites More sharing options...
westman Posted February 5, 2018 Author Share Posted February 5, 2018 (edited) It will not show me the error message. There is more than one of the same email in the data base. Edited February 5, 2018 by westman Link to comment Share on other sites More sharing options...
Ingolme Posted February 5, 2018 Share Posted February 5, 2018 Have you verified that the variable $email contains the correct value? Link to comment Share on other sites More sharing options...
westman Posted February 5, 2018 Author Share Posted February 5, 2018 yes Link to comment Share on other sites More sharing options...
Ingolme Posted February 5, 2018 Share Posted February 5, 2018 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 More sharing options...
justsomeguy Posted February 5, 2018 Share Posted February 5, 2018 Is that PDO? Because numrows doesn't always return the number of rows in a select query. You should use a count query instead. Link to comment Share on other sites More sharing options...
westman Posted February 5, 2018 Author Share Posted February 5, 2018 how do I do the count query? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2018 Share Posted February 5, 2018 SELECT COUNT(*) .... Link to comment Share on other sites More sharing options...
Ingolme Posted February 5, 2018 Share Posted February 5, 2018 I was under the impression it was MySQLi, which does use num_rows for SELECT statements. Link to comment Share on other sites More sharing options...
westman Posted February 5, 2018 Author Share Posted February 5, 2018 it is MySQLi Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2018 Share Posted February 6, 2018 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 More sharing options...
westman Posted February 6, 2018 Author Share Posted February 6, 2018 could you give a link please Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2018 Share Posted February 6, 2018 The manual is at php.net, you really need to know where it is to avoid having to wait 6 hours for someone to give you a link to it. There's a search bar on the top right where you can type any function name. http://php.net/manual/en/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now