0

I am trying to display an alert box using javascript in my login php file.

When a user logged in using a wrong username or password, then a messagebox will display.

This is what i have so far:

$query="SELECT * FROM info WHERE username ='$user' && password ='$pass' ";
		  $res=mysql_query($query);
		  if (mysql_num_rows($res) == 0) {
		           echo"<script language="javascript">window.alert('Invalid password.')</script>";
				   echo "<br>";
		     }
		   else {
				   echo "Access Granted";
				   echo "<br>";
		         }

Can't figure it out.

Edited by abelingaw: n/a

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by asprin
0

You should escape the double quotes in line 4:

echo"<script language=\"javascript\">window.alert('Invalid password.')...
0

The answer has already been posted, but for the sake of easiness I'm giving you the complete code:

if (mysql_num_rows($res) == 0) {
echo"<script language='javascript'>window.alert('Invalid password.')</script>";
echo "<br>";
}
else {
echo "Access Granted";
echo "<br>";
}

Edited by asprin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.