I want to have a simple web page with fields for userName and password.Once a user enters the correct userName and password and press logIn button then it should display an applet. Here's my code.
<?php
$un=$_POST["username"];
$pw=$_POST["password"];
$log=$_POST["Login"];
$con=mysqli_connect("localhost","root","","");
if(mysqli_connect_errno($con))
{
echo "Failed to connect".mysqli_connect_error();
}
mysqli_select_db($con,student);
$query="SELECT * FROM studentinfo WHERE stName=$un AND stP=$pw";
$result=mysqli_query($con,$query);
$num_rows = mysqli_num_rows($result);
if($log){
if($num_rows==1){
$isLogged=true;
}
else{
echo "Error log In.Invalid username or password";
$isLogged=false;
}
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User LogIn</title>
</head>
<body>
<form method="post">
<label>Username<input name="username" type="text" /></label> <label>Password<input name="password" type="password" /></label>
<input name="cmd" type="submit" value="Login" />
</form>
<?php if($isLogged) {?>
<applet code="studentWeb.html" width="32" height="32" alt="Couldn't launch applet" title="Student Details">
</applet>
<?php }?>
</body>
</html>
Right now it gives an error as
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in
and it doesn't open up a applet even when correct username and password has been entered.
Edit: After I changed to action="logindata.php" in the form, here's the logindata.php
<?php
$connect=mysqli_connect("localhost","root","");
if(mysqli_connect_errno($connect))
{
echo "Failed to connect".mysqli_connect_error();
}
mysqli_select_db($connect,"student") or die("couldn't connect to db");
$un=$_POST["username"];
$pw=$_POST["Password"];
$sql="SELECT * FROM studentinfo WHERE stUserName='$un' AND stPassword='pw'";
$query=mysqli_query($connect,$sql) or die("couldn't find values");
if($query){
include_once("studentWeb.html");
}
else{
echo ("Invalid username or password");
}
?>
Why does this allow incorrect password and username ?