私は$contact_id
を返すようにしたいが、私が得るすべてがある:それは帰国しなければならない なぜ私のmysqli_fetch_assocが機能していないのですか?
:the user id is 11
success.
the user id is
は、例えば、私のinsert.htmに、私は$ CheckContact入力します。これは私のuser
テーブルです:
そして、私は私のブラウザのアドレスバーに再びcheckcontact.php
をクリックした場合、その後私が取得:
the user id is 23
それは関係なく$CheckContact
が何であるかを、常に23ません。 何が間違っているか教えていただけますか?ここに私のコードは次のとおりです。
<?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'はnullになり、今設定されているので' isset'のチェックに合格しています。代わりに '!empty 'を使用してください –