我认为这应该有效但不是......
基本上我正在尝试检查mysql db以查看是否有符合2个变量的记录..如果是,则执行其他操作时不做任何事情。结果总是没有。
$result = mysql_query("SELECT 'lastname' FROM 'Cust_Releases' WHERE 'lastname' = '$usercheck' AND 'TripID'= '$RLtripid'");
echo $result;
if(mysql_num_rows($result) == 0) {
echo"no";// row not found, do stuff...
}
else {
echo"yes"; // do other stuff...
}
答案 0 :(得分:1)
首先,停止使用mysql_ *函数,因为从PHP 5.5.0开始不推荐使用此扩展。
第二个总是在数据库名称,表名和列名周围使用(`)符号。
您使用的保留字为RELEASE
。
$sql = "SELECT `lastname` FROM `Releases` WHERE `lastname` = '$usercheck' AND `TripID` = '$RLtripid'";
答案 1 :(得分:1)
$result = mysql_query("SELECT lastname FROM `Releases` WHERE lastname = '$usercheck' AND TripID= '$RLtripid' LIMIT 1");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
echo $result;
if(mysql_num_rows($result) == 0) {
echo"no";// row not found, do stuff...
}
else {
echo"yes"; // do other stuff...
}
答案 2 :(得分:0)
调试是编程中非常重要的事情。首先要确保varibales $ usercheck和$ RLtripid包含值。
----------------------- $sql = "SELECT `lastname` FROM `Cust_Releases` WHERE `lastname` = '$usercheck' AND `TripID`= '$RLtripid'"; echo $sql; $result = mysql_query($sql); ....-------------------
答案 3 :(得分:-1)
Try this code. It will help you
$result = mysql_query("SELECT COUNT( * ) from Cust_Releases lastname = '$usercheck' AND TripID= '$RLtripid'");
if($result == 0) {
echo"no";// row not found, do stuff...
}
else {
echo"yes"; // do other stuff...
}