我想回到$contact_id
,但我得到的是:为什么我的mysqli_fetch_assoc不工作?
success.
the user id is
例如,在我的insert.htm我输入$ CheckContact:
应该返回:the user id is 11
。这是我的user
表:
如果我在浏览器地址栏再次点击checkcontact.php
然后我得到:
the user id is 23
它总是23,无论什么$CheckContact
是。 你能告诉我什么是错的吗?这里是我的代码:
<?php
require('dbConnect.php');
$CheckContact = $_POST['phonenumber'];
$sql = "SELECT * FROM user WHERE username = '$CheckContact'";
$result = mysqli_query($con, $sql);
$check = mysqli_fetch_array($result);
//if $CheckContact is in the user table...
if(isset($check)) {
echo 'success.' . "<br>";
// get the associated rows of $CheckContact
$row = mysqli_fetch_assoc($result);
// get the associated user_id in that row
$contact_id = $row["user_id"];
echo "the user id is ", $contact_id;
}
//if $CheckContact is NOT in the user table...
else {
echo 'failure';
}
?>
你打开了PHP中的错误报告吗? –
你可以从insert.htm分享你的表单吗? –
在您的查询失败的情况下,可能会发生此问题。 '$ check'将为空,并且因为它现在被设置,所以它传递'isset'的检查。而是使用'!empty' –