I have 2 table names courses and institution. Here is my query:
CREATE TEMPORARY TABLE
IF NOT EXISTS temp AS (SELECT course_name, ins_name
FROM courses
where course_name='ACCA') ;
select institution.ins_name, address, contact, website,
email from institution join temp on institution.ins_name = temp.ins_name
And here is my php script:
<?php
session_start();
include('db_connect.php');
$sql="CREATE TEMPORARY TABLE
IF NOT EXISTS temp AS (SELECT course_name, ins_name
FROM courses
where course_name='ACCA') ;
select institution.ins_name, address, contact, website, email from institution join temp on institution.ins_name = temp.ins_name";
$result= mysqli_query($conn, $sql) or die("MySQL error: " . mysqli_error($conn));
while ($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ins_name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>"
?>
I can't figure out what the problem is. The error i get is:
MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select institution.ins_name, address, contact, website, email from institution j' at line 6
What am i doing wrong?