我有一个PHP代码,在执行时给出错误。 任何人都可以指出我的错误。

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";
}
  1. Please check if you are able to connect to database or not (database name, username and password to connect to database is correct or not)
  2. Check if table name user exists

Do share contents of conn.php if you are unable to resolve the issue

On a separate note

  1. please use mysqli instead of mysql as it is deprecated
  2. modify your query to: $mysql_qry ="select * from user where username = '$user_name' and main_password '$user_pass';"; . like is a very expensive operation

I 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​.