即使数据库中存在值,也始终执行else子句

即使数据库中存在值,也始终执行else子句

问题描述:

    $sql="SELECT * FROM manifest WHERE (awb_no = '$var')";
    $result=mysql_query($sql);  
    if($result==$var)
    {
     echo "tracking id present in the manifest</br>";
    }
     else
    {
      echo "trackingid not present<br>";
      exit(0);
    }

When i retrieve data from database and check it against the data i have entered,even though the data entered is correct and present in the database it executes the else clause.where am i going wrong? please help!

Try to count the rows from your query so try this:

$sql = "SELECT * FROM manifest WHERE (awb_no = '$var')";
$result = mysql_query($sql);  
if(mysql_num_rows($result) > 0) {
    echo "tracking id present in the manifest</br>";
} else {
    echo "trackingid not present<br>";
    exit(0);
}

Btw mysql is depricated so use PDO or mysqli