My code does not error, but neither does it compile. Nothing happens :/

Asked

Viewed 207 times

-2

I do not know what happens in the code. It does not error, but also does not Insert and does not go to the Login screen and also does not enter the "error" inserir a descrição da imagem aqui

  • 3

    Don’t use images to show your code, other people may need to do tests and no one wants to keep typing everything you’ve ever written. I advise you to edit the question and enter the code into it.

  • 3

    Its code has problems of logic, SQL injection, and a race condition in the Insert, besides being structured in a much more complex way than necessary. Apart from that, as already mentioned, it has inadequate use of addslashes. It would be nice to take a better look and redo from scratch, learning from other site posts. Fixing this would be more work than redoing, so it pays to start right again with more theoretical knowledge (to give less maintenance later, inclusive). Search the site about SQL injection, avoid insertion more than once, secure password and also about addslashes.

1 answer

1

How to make the diagnosis?

To make this diagnosis of what happens, you have to analyze what is being passed through the POST request and see if everything is being provided to your PHP application, check the correct spelling of the variables hits (uppercase, lowercase, some error, etc.) In your case, this must be it...

Why does not display error?

It does not display the error that is within Else because it validates (and enters) the first

if(isset($_POST['agencia']) && empty($_POST['agencia']) == false)

and goes on to the internal validations that do not have LSE, failing either of these (account or password)...

Correcting the error

Add a few more elses there to debug your application in an easier way, informing the user each error, in the case of the second if puts an Else and echoes: "You must enter the account number", in the next validation, echoes: "you must enter the password", and so on... If an if passes, and an error occurs internally, it does not go to the former’s Else.

Extra tip

Your code is susceptible to SQL injection attacks... You have to prepare the input variables before with $sql->mysql_real_escape_string($_POST['agencia']). The addslashes function is not recommended for this as this answer.

  • The tips are good, just a detail: unfortunately it is using PDO instead of mysqli, so the "extra tip" does not apply. Qq way, is given the +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.