0

I had a problem with my single webpage. I want to display some infos from a database. So, I made the connection and then I wrote the HTML so that they will be displayed, but when I run that in my website, the only thing that is displayed, is a blank white page.

My PHP code is:

<?php

  $query = "SELECT * FROM `test_database` WHERE subcategory='number'";
  $show_id = filterTable($query);


  $query_num_rows = mysql_num_rows($query_run);

  if ($query_num_rows >= 1 ) {
      echo $query_num_rows.' results found:<br>';
      }
  } else {
      echo 'no result';
  }

// function to connect and execute the query
function filterTable($query)
{
    $connect = mysqli_connect("host", "user", "pas", "table");
    $filter_Result = mysqli_query($connect, $query);
    return $filter_Result;
}

?>

And the HTML:

<!DOCTYPE html>
<head>
</head>
<body>

     <?php while($row = mysqli_fetch_array($show_id)):?>

     <!-- Trigger/Open The Modal -->
     <div class="center">
        <button id="myBtn">
            <span><?php echo $row['id'];?></span>
            <?php endwhile;?>
        </button>

    </div>

</body>
</html>
LeoBl
  • 27
  • 6
  • Possible duplicate of [Can I mix MySQL APIs in PHP?](https://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – RiggsFolly Aug 31 '18 at 09:56

1 Answers1

0

Your "if" has 2 closing curly braces...

[edit] plz consider using a good IDE, Enable the display of php errors (in DEV server only) and have a look to your server logs.

[edit] As already said by many comments

  • You are mixing msql_ and mysqli_ functions
  • $query_run passed as parameter to mysql_num_rows() function, is not initialized

[edit] mysqli_connect("host", "user", "pas", "table"); <--- this should be a DB name

And "SELECT * FROM test_database WHERE subcategory='number'" <--- the from should be a table name...

Constantin
  • 1,258
  • 10
  • 9
  • 1
    not really an answer, that doesn't solve the OP's issue, it is better to be a comment rather than an answer. – ThS Aug 31 '18 at 10:00
  • Actually, it may solve the "white page issue". But yes there is more than one issue in his code. – Constantin Aug 31 '18 at 10:01
  • 1
    we call it an answer if and only if it solves the issue and not partially solve it. There are many other errors in the OP's question, I did mention some in the comments. – ThS Aug 31 '18 at 10:04
  • It is the main issue in his code. It is certainly the first cause of the blank page. – Constantin Aug 31 '18 at 10:06
  • Its definitely NOT the main issue in this code! I doubt it will actually get to the IF statement before it crashes – RiggsFolly Aug 31 '18 at 10:15
  • @RiggsFolly of course, but how can I make it function correctly, except from the mysqli_num_rows() that I changed, I can't something else that causes the problem – LeoBl Aug 31 '18 at 10:31
  • `$query_num_rows = mysqli_num_rows($show_id);` – RiggsFolly Aug 31 '18 at 10:35
  • That's what I changed from the beginning but nothing happened. I even run the code without the if statement and the declaration but still I get the white page. – LeoBl Aug 31 '18 at 10:45
  • 1
    @RiggsFolly you doubt, I don't. Parsing issue has more priority than calling a function with a null variable as parameter... Try it if you don't believe me... – Constantin Aug 31 '18 at 11:33