php - Handling no results returned from a prepared select statement -


I am trying to create a basic login system. Username Username = password that is posted in the form that is in the following code:

  if (isset ($ _ POST ['submit']) {$ sql = " SELECT username, password with tbl_users WHERE user name =? And password =? "; $ Stmt = $ mysqli- & gt; Ready ($ sql); if (! $ Stmt) {dead (" Preparation failed: (" MySqli-> errno. ")". $ Mysqli-> Error);} $ Username = $ _POST ['Username']; $ password = $ _POST ['password']; var_dump ($ user name); var_dump ($ Password); $ Bind_result = $ stmt- & gt; Bandwidth ("ss", $ user Name, $ password); if (! $ Bind_result) {echo "binding failed: (". $ Stmt-> errno. ")". $ Stmt-> error;} $ Execute_result = $ stmt- & Execute_result {echo} "Execution failed: (". ($ Return_username, $ return_password); while ($ stmt-> fetch)} {var_dump ($ return_username); var_dump ($ returned_password); if ($ username === $ returned user & amp; $ Password === $ returned password) {echo "Now you are logged in!"; } Else {echo "wrong username or password"; }}  

If I type the correct username and password, then everything works fine and it logs in correctly when I enter the wrong information, then either wrong The database starts using a password or username, which is not in the database "Incorrect username or password" line has never worked

I am new to using ready statement , But I still have this Once that, when I force the results, I can only enter those loops that are using the fetch. However, if no result is found, then that loop never runs, so I have no way of testing whether or not a result has been found in the query. I'm probably missing something obvious here, but I'm trying to solve this all in the morning and it's sending me crazy.

The problem you are having is based on the logic applied to your code. If any user does not recover from the database then the code that checks the correct username and password is never run, you can fix this by simply changing some lines of your code, try it:

  // Your code is at this time ($ stmt-> Fetch ()) {var_dump ($ return_username); Var_dump ($ returned_password); If ($ username === $ returned user & amp; $ password === $ returned password) {echo "e are now logged in you!"; } Else {echo "wrong username or password"; }} // changes the location for that ($ stmt-> fetch ()) {var_dump ($ return_username); Var_dump ($ returned_password); } If ($ username === $ returned user & amp; $ password === $ returned password) {resonates "resume you are now!"; } Else {echo "wrong username or password"; }  

Hope that helps solve your problem, happy coding.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -