0

I want to display information about a movie after the user searches the movie's name (Nume Film). I tried the code below.

    <?php  

    session_start();
    require 'connect.php';



    if(!empty($_GET['search']) && isset($_GET['search'])) {

    $searchedmovie = $_GET['search'];

    $sql = "SELECT * FROM filme WHERE Nume Film ='$searchedmovie'";
    $result = mysqli_query($connect,$sql);
    $row = $result->fetch_assoc(); 
    $check = mysqli_num_rows($result);  


    if($check > 0) {
        header("Location: movies.inc.php?info=exist");

    } else {
        header("Location: movies.inc.php?info=error");
    }       

    }

   if(isset($_GET['info']) && $_GET['info'] == 'exist') {
        echo $row['Nume Film'].' '.$row['Actori'].' '.$row['Data aparitiei'].' '.$row['Box Office'].' 
         '.$row['Rating'];
   } elseif (isset($_GET['info']) && $_GET['info'] == 'error') {
        echo '<p style="text-align: center; color: red; font-size: 20px;">Filmul nu este in baza de 
         date!</p>';
   }   

   ?>

The error I get is :

Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in /home/dlivadariu/public_html/CINEfils/movies.inc.php:14 Stack trace: #0 {main} thrown in /home/dlivadariu/public_html/CINEfils/movies.inc.php on line 14

The connect.php file is

    <?php

      $connect = mysqli_connect('localhost','username','password','databasename');

      if (!$connect){
         die('Conectarea la baza de date nu a reusit');
      }

     ?>       

The code for the form is :

    <form method="GET" action="movies.inc.php" autocomplete="off">
       <input type="text" name="search" placeholder="Cauta un film...">
       <input style="background-color: #111111; color: white; cursor: pointer;" 
           type="submit" value="Cauta">
     </form>

What should the problem be? If I try to search the movie by its Rating:

the code

    $sql = "SELECT * FROM filme WHERE Rating='$searchedmovie'";

I am given this error:

Notice: Undefined variable: row in /home/dlivadariu/public_html/CINEfils/movies.inc.php on line 28

If I search a movie's name now, this line works

    elseif (isset($_GET['info']) && $_GET['info'] == 'error') {
        echo '<p style="text-align: center; color: red; font-size: 20px;">Filmul nu este in baza de 
         date!</p>';
   }   
brombeer
  • 8,716
  • 5
  • 21
  • 27
dadvilfed
  • 1
  • 1
  • 1
    Error message says that `$result` is false. Check SQL error. I think col name with space (Nume film) should be in quotes `. – pavel Mar 17 '21 at 12:22
  • Does this answer your question? [Call to a member function fetch\_assoc() on boolean in ](https://stackoverflow.com/questions/35669088/call-to-a-member-function-fetch-assoc-on-boolean-in-path). When facing an error message like this, searching on that error message is usually the fastest way of getting an answer since most PHP error messages have been asked about and answered before. – M. Eriksson Mar 17 '21 at 12:31
  • OK, so: @MagnusEriksson that article really helped, I had an error in the SELECT and yes pavel that was the problem, I put name of the column in quotes Now I don't have any errors, but it still doesn't function. Whatever I type I get the else message that there are no movies in the database – dadvilfed Mar 17 '21 at 12:49
  • Questions should only contain one issue. If the first was solved by that duplicate link, then this question has been answered. For your other issue, post a new question that only focuses on that specific issue (only post the relevant code and explain the expected behavior and issue in detail) – M. Eriksson Mar 17 '21 at 13:27

0 Answers0