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>';
}