DELETE for MySQL is not running.

Asked 2 years ago, Updated 2 years ago, 42 views

Creating a bulletin board site.
I am connecting to MySQL from PHP using PDO, but the DELETE statement does not run.
You can INSERT the database with the add.php file, but
The delete.php file is not working properly and the DELETE statement is omitted.
in the file below I look forward to hearing from you.

PHP 5.5
MYSQL 5.5 Ubuntu 14.04 LTS (Vagrant Virtual Environment)
Apache 2.4

<?php
$user="root";
$pass = "abcd4649";
try{
    if(empty($_GET['thid']))throw new Exception(error);
    $thid = $_GET ['thid'];
    $dbh=new PDO('mysql:host=localhost;dbname=db1; charset=utf8',$user,$pass);
    $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    $sql="DELETE FROM title WHERE thid=?";
    $stmt = $dbh->prepare($sql);
    $stmt->bindValue(1,$title,PDO::PARAM_STR);
    $stmt->execute();
    $dbh = null;
    The echo "ID:".htmlspecialchars($thid,ENT_QUOTES,'UTF-8')." deletion is complete.";
    echo"<a href='index.php'>Back to top page</a>";
} catch(Exception$e){
    echo "Error Occurred:".htmlspecialchars($e->getMessage(),ENT_QUOTES,'UTF-8')."<Br>";
}
?>
<?php
$user="root";
$pass = "abcd4649";
$title=$_POST ['title'];
try{
    $dbh=new PDO('mysql:host=localhost;dbname=db1; charset=utf8',$user,$pass);
    $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    $sql="INSERT INTO title(title) VALUES(?)";
    $stmt = $dbh->prepare($sql);
    $stmt->bindValue(1,$title,PDO::PARAM_STR);
    $stmt->execute();
    $dbh = null;
    The echo" thread creation is complete.<br>";
    echo "<a href=index.php>Back to top page</a>";
} catch(PDOException$e){
    echo "Error Occurred:".htmlspecialchars($e->getMessage(),ENT_QUOTES,'UTF-8');
    die();
}
?>

php mysql

2022-09-29 22:27

1 Answers

It seems that the $title variable is not set in delete.php?


2022-09-29 22:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.