我试图知道数据库中是否存在现有数据,我们尝试使用现有用户名,根据我的编码,它应该是"已经存在",但结果是" ;继续&#34 ;.你能指出我错在哪里吗?
$query = mysql_query("SELECT * FROM `membership` WHERE `username` = '$username'");
if (mysql_num_rows($query) > 0){
echo "exists already";
}
else {
echo "proceed";
}
答案 0 :(得分:0)
这应该有效
$str = "select SQL_CALC_FOUND_ROWS * from table where username=".$your_value;
$con=db_connect();
$result1 = mysql_query($str,$con);
$str1 = "SELECT FOUND_ROWS() as totalRecord";
$result2 = mysql_query($str1,$con);
$totalRecords = mysql_fetch_array($result2);
if ($totalRecords[0]>0){
echo "exists already";
}
else{echo "proceed";}
也尝试使用 mysqli或pdo ,因为mysql已被删除...