Im novice to php. I am trying to make user authentication form in php. Here is my code:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ORMS Login Form</title>
</head>
<body>
<form method="post" action="validate_login.php" >
<table border="1" >
<tr>
<td><label for="user_name">Username</label></td>
<td><input type="text"
name="user_name" id="user_name"></td>
</tr>
<tr>
<td><label for="pass">Password</label></td>
<td><input name="pass"
type="password" id="pass"></input></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/>
<td><input type="reset" value="Reset"/>
</tr>
</table>
</form>
</body>
</html>
Validate_login.php:
<?php
// Grab User submitted information
$name = $_POST["user_name"];
$pass = $_POST["pass"];
// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("orms",$con);
$result = mysql_query("SELECT user_name, pass FROM waiterAccount where user_name=$name"); //LINE 20
$row = mysql_fetch_array($result);
echo $row["user_name"]." ".$row["pass"]."<br>";
if($row["user_name"]==$name && $row["pass"]==$pass)
echo"You are a validated user.";
else
echo"Sorry, your credentials are not valid, Please try again.";
?>
Output is:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\orms\validate_login.php on line 20
Sorry, your credentials are not valid, Please try again.
Im not getting why error is coming coz when i run the line 20 query in my database it runs fine.