I'm trying to check my data before inserting it into the database, but this error always appear
What I have tried:
<pre>if(isset($_POST['submit'])){
$first_name = test_input($_POST["firstname"]);
$last_name = test_input($_POST["lastname"]);
$id = test_input($_POST["member_id"]);
$username = test_input($_POST["username"]);
$password = test_input($_POST["password"]);
$email = test_input($_POST["email"]);
$membertype = test_input($_POST["membertype"]);
$phone = test_input($_POST["phonenumber"]);
$department = test_input($_POST["department"]);
$query = "SELECT * FROM lms WHERE ID='".$id."' OR email='".$email."' OR user_name='".$username."' ";
$resultdata = mysqli_query($link , $query);
$data = mysqli_fetch_array($resultdata, MYSQLI_NUM);
if($data[0] > 1) {
echo "User Already in Exists<br/>";
}
else
{
$sql = "INSERT INTO `member` (`ID`, `first_name`, `last_name`, `member_type`, `password`, `email`, `phoneNo`, `department`, `user_name`)
VALUES ('$id', '$first_name', '$last_name','$membertype','$password','$email','$phone','$department','$username')";
if (mysqli_query($link,$sql))
{
echo "You are now registered<br/>";
}
else
{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
i have tried also this
$results = mysql_num_rows($resultdata);
and
$user = mysqli_fetch_assoc($resultdata);
but it gives me the same error, I know this error appears because of the query return false result, but I don't what else should I use