Jump to content
Larry Ullman's Book Forums

Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given

Recommended Posts

Can someone please tell me how to fix this?  here is the code

 function getPosts()
    $posts = array();
    $posts[0] = $_POST['course'];
    $posts[1] = $_POST['level'];
    $posts[2] = $_POST['section'];
    return $posts;

if (isset($_POST['insert'])) {
  $data = getPosts();

 $existing_Query ="SELECT * FROM `class` WHERE `course`='$data[0]' OR `level`='$data[1]' OR `section`='$data[2]'";
  $existing_Result = mysqli_query($con, $existing_Query);
  if(0 < mysqli_num_rows ($existing_Result)){
    echo '<script type="text/javascript">
                      alert("your entry is already in the class. please choose another class.");
  } else {
    $insert_Query = "INSERT INTO `class` (`course`, `level`, `section`) VALUES ('$data[0]', '$data[1]', '$data[2]')";
    $insert_Result = mysqli_query($con, $insert_Query);
    if ($insert_Result) {


Link to comment
Share on other sites

That means your query didn't run properly due to an error. I suspect it's because you can't return an array from a function like that (as an aside, that's not a good use of a user-defined function). If you start by printing out the value of $existing_Query you can confirm this. 

Link to comment
Share on other sites


  • Create New...