This code is what i have tried to process the query, either delete or insert do not have affect.
The id is correct and conn.php is correct .
I just copy the sql query to phpmyadmin to test and it works.
And i put a echo "test"; between try{} it echo too.
Thank you
<?
include("../connection/conn.php");
session_start();
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// list out the pervious create list
//$id=$_GET['id'];
$id=3;
try{
$sql = 'INSERT INTO delete_list SELECT * FROM list WHERE ListID=?';
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="view.php"> Back</a>');
}
try{
$sql = 'INSERT INTO delete_user_list SELECT * FROM user_list WHERE ListID=?';
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="view.php"> Back</a>');
}
try{
$sql = 'INSERT INTO delete_require_attributes SELECT * FROM require_attributes WHERE ListID=?';
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="view.php"> Back</a>');
}
try{
$sql = 'INSERT INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?';
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
$count=$stmt->rowCount();
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="view.php"> Back</a>');
}
try{
$sql = 'INSERT INTO delete_list_sub SELECT * FROM list_sub WHERE ListID=?';
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="view.php"> Back</a>');
}
try{
$sql = 'DELETE FROM list WHERE ListID = ?';
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
}
catch(PDOException $e)
{
die ($e->getMessage().'<a href="view.php"> Back</a>');
}
echo "The list has been deleted.".$count." subscribers has been removed. <a href='view.php'> Back</a>";
?>
i added
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
and error is
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ListID' in 'where clause' Back
It doesn’t work because in order for variables to be interpolated you need to use double quotes (“) not single quotes. Single quotes makes it literally pass “$id” instead of the value.
But since you’re using PDO you should be using prepared statements! Like this:
The value of
$idreplaces the?EDIT: fixed the parameter