This is my code.
<?php
require "conn.php";
$user_name = "un";
$user_pass="123";
$mysql_qry ="select * from user where username like '$user_name' and main_password '$user_pass';";
$result = mysql_query($mysql_qry, $conn);
if(mysql_num_rows($result)>0){
echo "Login Success!";
}else{
echo "Invalid Username or Password!";
}
?>
Error message is attached herewith. enter image description here
Please check your $result
if it returns false and check your query error.
$result=mysql_query($sql);
if ($result==false)
{
die(mysql_error());
}
else
{
echo "Login Access";
}
user
existsDo share contents of conn.php
if you are unable to resolve the issue
On a separate note
mysqli
instead of mysql
as it is deprecated$mysql_qry ="select * from user where username = '$user_name' and main_password '$user_pass';";
. like
is a very expensive operationI think something wrong with your MySQL query function, try using
$result = mysqli_query($conn, $mysql_qry);
or
$result = mysql_query($mysql_qry);
instead of
$result = mysql_query($mysql_qry, $conn);
I am wondering how this point missed.. there is an error in your sql query. There is = or like operator missing after main_password. I would not recommend to check password in your query, you should fetch record with username and check password in if condition.
$mysql_qry ="select * from user where username like '$user_name' and main_password = '$user_pass'";
Hope this helps.