i am trying to run the following piece of SQL code in a php file
Select show_id, show_name
From (tv_shows JOIN distributes on D_SHOW_ID=SHOW_ID)
Where show_name= ‘Show Name’
(where 'Show Name' is a variable the the user passes in.) The SQL functions perfectly in mySQL but i just can't seem to print the results without errors occurring.
i tried
$mysqli = include ('./DBconnect.php');
$sql = 'SELECT show_id, show_name
FROM (tv_shows JOIN distributes ON D_SHOW_ID=SHOW_ID)
WHERE show_name= ? ';
$stmt = $mysqli-> prepare($sql);
// getting the variable from the user input
$showName = $_GET["name"];
//testing if the variable is passed through
echo $showName."is printed";
$stmt->bind_param('s',$showName);
$stmt-> execute();
$stmt -> bind_result($show_id,$show_name);
if ($stmt->fetch())
{
echo '<p> Show ID: '.$show_id.' Show Name'. $show_name.'</p><br>';
}
and it is giving me a "Call to a member function prepare() on null " error
i have a second php file that is called DBconnect.php which also seem to function correctly.
function get_mysqli_conn(){
$dbhost = "xxxxx";
$dbuser = "xxxxx";
$dbpassword = "xxxxx";
$dbname = "xxxxxx";
$conn = new mysqli($dbhost, $dbuser,$dbpassword,$dbname);
if (!$conn){
die ('Failed to connec to MySQL : (' . $conn->connect_errno.')' . $conn ->connect_error);
}else{
echo 'connected';
}
}