$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);
}
当我从数据库中检索数据并根据我输入的数据进行检查时,即使输入的数据是正确的并存在于数据库中,它也会执行else子句。我在哪里出错?请帮忙!
答案 0 :(得分:1)
尝试计算查询中的行,请尝试以下操作:
$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);
}
顺便提一下mysql
,因此请使用PDO
或mysqli