html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Validation Page</title>
</head>

<body onload="document.validate.name.focus();">

<div align="center" id="validate">
<form action="validate.php" method="post" name="validate" runat="server" title="This a validation form" >
<table width="200" border="1">
<tr>
<th scope="row">User Name </th>
<td><label>
<input name="name" type="text" id="name" />
</label></td>
</tr>
<tr>
<th scope="row">Password</th>
<td><label>
<input name="psw" type="password" id="psw" />
</label></td>
</tr>
</table>

<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
</div>
<p>
<?php
$con = mysql_connect("localhost","root","meghlan")
or die("There was an error in the connection".mysql_error());

$db = mysql_select_db("manjunk",$con)
or die("there was an error while selecting the database".mysql_error());

//Here is the php code for the balidation form
$name = $_POST["name"];
$psw = $_POST["psw"];
echo "You entered : ".$name." and ".$psw."<br />";
$sql = "select * from user where user = '$name' ";
$result = mysql_query($sql,$con)
or die("<br /> There was an error in the query <br />".mysql_error());
while($row=mysql_fetch_array($result))
{
if($row==$user)
break;
}

if(!$row)
echo "No Access";
/*echo '<script type="text/javascript>
document.validate.name.focus();
</script>';*/
else
echo " Acces";
?>
</body>
</html>


i get no access ...whereas i hve another script almost identical to this which works fine..


please help..

Try changing the if statement at the end of your script to the following:

if($row['user']=='' || !isset($row['user'])) {
echo "No Access";
/*echo '<script type="text/javascript>
document.validate.name.focus();
</script>';*/
} else {
echo " Acces"; 
}
?>
</body>
</html>

it doesnt prints no access

Well then what type of condition exactly do you want no access to display. Is it when no rows are found in the loop above or is it when the variable is empty. What type of if action do you want done?

try to change name $user to another variable name $uid or $uname sometimes the cookie keeps $user for database's username

you are using user variable many times change user variable name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.