php - mysqli_data_seek Function Returns Username Result, When Username Not in Database -
I have a function in which a named user is in my database, I have a message on my screen string value , Which just says my function works.
However, when I do not exist in the database, the name changes, I still get a string output that says that the function works. So I am trying to figure out how my argument in question has been messed up. What do I have:
users.php file:
& lt; Php function user_exists ($ user name) {$ db = "adult"; $ DbH = "localhost"; $ DbU = "root"; $ DbP = "Jeffrey 9"; // $ dbCon = mysqli_connect ($ dbH, $ dbU, $ dbp, $ db) connection to; $ Username = sanitize ($ username); // $ query = mysqli_query ($ dbCon, "SELECT COUNT (` user_id`) WHERE 'user name' = '$ user name' from `users`); return (mysqli_data_seek (mysqli_query ($ dbCon," SELECT COUNT (`user_id `) WHERE 'username' = '$ user name' from` users`), 0) == 1)? right wrong; }? & Gt;
Now here is the login page that processes a function to see if a user actually exists:
Login.php file:
& lt ;? Php included 'core / init.php'; If (user_exists ('raiders7') === true) {echo 'got user!'; } Die (); If (empty ($ _ POST) === incorrect) {$ username = $ _POST ['username']; $ Password = $ _POST ['password']; If (empty ($ user name) === correct || empty ($ password) === true) {$ errors [] = 'You must enter a username and password.'; } And if (user_exists ($ user name) === incorrect) {$ errors [] = 'Can not find the username that you have registered? '; }}? & Gt;
Of course, I have a line and a user in the database when the string user_exists ('raiders7')
, I got the user!
on my index page.
But when it is user_exists ('something else')
it still got the user! On the
page.
How is it like this? Page should be empty if the user does not exist.
Finally, I am using another function to store my data like this:
General.php file: < / P>
& lt ;? Php function syntax ($ data) {$ db = "adult"; $ DbH = "localhost"; $ DbU = "root"; $ DbP = "Jeffrey 9"; // $ dbCon = mysqli_connect ($ dbH, $ dbU, $ dbp, $ db) connection to; Return mysqli_real_escape_string ($ dbCon, $ data); }? & Gt;
Do not know that the last part is helpful, but someone can help me fix my argument how I got the user!
can stop receiving messages, thanks when the user is not present in my test database.
You should get results to get the right / desired result.
What happens is that you only move the pointer, of course always the row set in index 0
+ ---------- ----- - + | COUNT (user_id) | // Even if the count is zero, your position will still be true ---------------- + | 0 | + ---------------- +
Even when the user name is incorrect / does not exist!
Get results then calculate correctly
$ username = $ dbCon-> Real_escape_string ($ username); $ Query = mysqli_query ($ dbCon, "SELECT COUNT" (`user_id`) as the total` user` WHERE'username '=' $ user name '); $ line = $ query-> fetch_assoc ( ); $ Count = $ row ['total']; // Get results! If ($ count> 0) {// true} else {// false}
Or @fred said, then just use num_rows
and better tie it:
$ sql = 'Select' from the user 'where `username =? '; $ Select = $ dbCon-> Ready ($ sql); $ Select- & gt; bind_param (' s', $ username); $ Select-> Executed (); if ($ Select-> num_rows & gt; 0) {// found} else {// not found}
Comments
Post a Comment