I want to return $contact_id
but all I get is :
success.
the user id is
For example, in my insert.htm I enter $CheckContact :
It should be returning : the user id is 11
. This is my user
table :
And if I click checkcontact.php
again in my browser address bar then I get :
the user id is 23
It's always 23, no matter what $CheckContact
is.
Can you tell me what is wrong ? Here is my code :
<?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';
}
?>