我有这段代码。
$stmt4 = $conn->prepare("SELECT likedFour FROM UserData WHERE username = 'jim'");
现在,当username = jim时,这应该找到LikeFour行的值。
我有这个if语句。
if ($stmt4 == '') {
}
这不应该检查该值是否为空? 它不起作用。
这是完整的代码。
$stmt = $conn->prepare("SELECT * FROM UserData WHERE username = ?");
$stmt->bind_param('s',$username);
//$username = $_POST["username"];
$username ="jim";
$stmt->execute();
$stmt->store_result();
$stmt1 = $conn->prepare("SELECT likedOne FROM UserData WHERE username = ?");
$stmt1->bind_param('s',$username);
//$username = $_POST["username"];
$username ="jim";
echo "debug 2";
if ($stmt->num_rows == 0){ // username not taken
echo "debug 2.5";
die;
}else{
$result = mysqli_num_rows($stmt1);
echo "debug 2.7";
echo var_dump($stmt1);
if ($stmt1 == 00000){
echo "debug 3";
$sql = $conn->prepare("UPDATE UserData SET likedOne=? WHERE username=?");
$sql->bind_param('ss',$TUsername,$Username);
// $TUsername = $_POST["TUsername"];
// $Username = $_POST["username"];
$TUsername = "test";
$Username = "jim";
}
}
答案 0 :(得分:0)
我会这样做:
$stmt4 = $conn->prepare("SELECT * FROM UserData WHERE username = 'jim'");
//This should grab the entire row where username == jim
然后
if(!$stmt4[likedFour]){
echo "Nothing has been found";
}
如果其他一切都很好,那应该是完美的。
答案 1 :(得分:-1)
尝试放置两个等号而不是一个。第一个等号表示您正在设置条件,而第二个等于表示您正在检查是否有东西等于第一个变量。