php - delete the data from database for multiple table

I have a database that contains 5 tables named(class8, class9, class10, class11, class12
) each table contains 5 columns named(physics8, chemistry8, maths8, biology8, english8
). Just replacephysics8
withphysics9
forclass9
and so on. I have fetched all five tables data in a webpage. I had given an option to delete. where the user can able to delete any particular data for a particular column and for a particular table.
How can I delete with multiples table? my database contains 4null
in each row of every table
I have tried working with similar questions on but it didn't solve my problem
Below is my database structure:
Below is my code forDELETE
<?php
session_start();
include('database.php');
$sql = "DELETE from (
DELETE from `class8`
UNION
DELETE from `class9`
UNION
DELETE from `class10`
UNION
DELETE from `class11`
UNION
DELETE from `class12`
) classes
WHERE classes.teacher_id = :id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id', $_SESSION['teacher_id']);
if($stmt->execute())
{
echo "<script type='text/javascript'> alert('delete sucessfull');
window.location='prospectcorse.php';
</script>";
}
else
{
echo "<script type='text/javascript'> alert('error');
window.location='prospectcorse.php';
</script>";
}
?>
Below is the error I get
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION DELETE from
class9
UNION DELETE fromclass10
UNI' at line 2 in C:\xampp\htdocs\kridha\delete.php:19 Stack trace: #0 C:\xampp\htdocs\kridha\delete.php(19): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\kridha\delete.php on line 19
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.