这是用于检查行中username = something
的值的代码$stmt1 = $conn->prepare("SELECT likedOne FROM UserData WHERE username = ?");
$stmt1->bind_param('s',$username);
//$username = $_POST["username"];
$username ="jim";
$stmt1->execute();
$stmt1->store_result();
此法规会检查Value是否为空?
if ($stmt1 == ''){}
它不能正常工作。
答案 0 :(得分:1)
试试这个
$stmt1->num_rows > 0
或
$res = $stmt1->fetch();
if( !empty( $res )
{
}
现在您的代码看起来像
$stmt1 = $conn->prepare("SELECT likedOne FROM UserData WHERE username = ?");
$username ="jim";
$stmt1->bind_param('s', $username);
$stmt1->execute();
$stmt1->store_result();
if($stmt1->num_rows > 0)
{
//data retrive condition here
}
答案 1 :(得分:0)
您可以通过多种方式查看,
if ($stmt1 === null){ } // This checks if the variable, by type, IS null.
OR
if (empty($stmt1)){ }
OR
if (!isset($stmt1)){ }
!isset($stmt1)
检查变量是否未定义,如果变量是空的,则不会。