-3

I am writing a simple login page with just a name and a password. I created some users and passwords in my database. I wrote validation code, which would show a Javascript alert when the user hits the login button. I am only showing you a sample of the code that I think may be causing the issue. Here is the Javascript, which is in my head section. I commented out certain things. The issue I have is that the Javascript is not showing the alerts after I hit the login button.

I'm trying to delete the question sorry.

Jorgan
  • 49
  • 3
  • 10
  • 2
    `if($n = row['name'] && $p = row['pwd'])` -- did you mean to do assignment rather than comparison here? – jdgregson Apr 17 '18 at 21:11
  • 1
    What you need is Ajax. – Reza Saadati Apr 17 '18 at 21:13
  • 1
    Should be `$row` not `row`. I dont understand the context in which you are executing the code. – nikksan Apr 17 '18 at 21:14
  • why not just place the alert in the echo, since its only 1 line a JS `` – SC92 Apr 17 '18 at 21:19
  • 1
    If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5, and completely removed in PHP 7.0 (which is so old it [no longer even receives active support](http://php.net/supported-versions.php)). Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. It's 2018 and this isn't funny anymore… – ChrisGPT was on strike Apr 17 '18 at 21:28
  • 1
    Also, _**never**, under **any** circumstances, should you be storing plain-text passwords!_ Use [`password_hash()`](https://secure.php.net/manual/en/function.password-hash.php) and [`password_verify()`](https://secure.php.net/manual/en/function.password-verify.php) instead. – ChrisGPT was on strike Apr 17 '18 at 21:30
  • @jdgregson I meant to compare it to check if the name and password inputted matches a name and password in the row. – Jorgan Apr 17 '18 at 21:34
  • @Jorgan Did you try using `==` or `===` for the comparisons on that line? – jdgregson Apr 17 '18 at 21:39
  • If you want a js call to run it has to be inside a `` tag set. But first fix the PHP errors – RiggsFolly Apr 17 '18 at 21:39
  • @SC92 Did that. – Jorgan Apr 17 '18 at 22:06
  • @jdgregson I test the == and the === for the comparisons and it still it didn't work. – Jorgan Apr 17 '18 at 22:06
  • @Jorgan Is the `validateLogin()` function actually being called by on the page that the username and password is posted too? It would be helpful if you updated your answer with your username and password form. – jdgregson Apr 17 '18 at 22:13
  • @jdgregson I updated my question by adding the form code and added the changed php code. – Jorgan Apr 17 '18 at 22:18
  • @jdgregson After I updated my code, my program was doing the same, but now of the sudden, the form disappears when clicking the login button. – Jorgan Apr 17 '18 at 23:05
  • @jdgregson OOPS I MESSED UP! I accidentally deleted my login code. – Jorgan Apr 17 '18 at 23:15
  • Now I added back in my login code. Sorry. – Jorgan Apr 17 '18 at 23:22

2 Answers2

0

You need to write it like that

echo "<script> success(); </script>";


echo "<script> error(); </script>";
mooga
  • 3,136
  • 4
  • 23
  • 38
  • I tried that and I correct the row to $row code and my login still doesn't print the errors or success. – Jorgan Apr 17 '18 at 21:35
0

The problem is in the

echo "success();"; and
echo "error();";

What you are actually doing is outputting to the html page the string "success();" and "error();" Rather use

echo "<script> success(); </script>";
echo "<script> error(); </script>";

  • I tried that and I correct the row to $row code and my login still doesn't print the errors or success – Jorgan Apr 17 '18 at 21:35