我有按钮,onclick我得到这样的链接://..../ update_news.php?newsID = 112&& value = delete
使用此代码:
'<td style="width:50px;"> <u> <b><a href="update_news.php?newsID='.$row['newsID'].'&&'.'value=delete'.'">'.'<img src="src/img/delete.png" /></b></u></td></a>';
然后我尝试使用此类删除行,但它不起作用:
class Delete{
private $db;
public function __construct(){
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function Delete($title, $date, $short_description, $description){
$newsID = $_Get['newsID'];
$delete = $_Get['delete'];
if(isset($delete))
{
$sql = "DELETE FROM `News` WHERE newsID= :newsID";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':newsID', $_GET['newsID'], PDO::PARAM_INT);
$stmt->execute();
echo "WORKS";
}
else
{
echo "Papapapapa";
}
}}
我称这个班:
$object = new Delete();
$object->news($newsID, $title, $date, $short_description, $description);
谢谢有人会帮助我。
答案 0 :(得分:1)
在我看来,你应该做的第一件事就是重命名你的Delete
函数,使它没有大写,所以你不会把它与你的班级混淆。
我要尝试的第二件事实际上是调用(很快将被重命名)delete
函数,因为现在你正在调用一个名为news
的函数,这可能是一个错字或代码我们可以'看。请尝试使用$object->delete(...)
代替$object->news(...)
。
答案 1 :(得分:1)
为什么要调用news()方法?您将方法写入构造函数。你必须写成这样一个类:
class Delete{
private $db;
public function __construct(){
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function DeleteNews($title, $date, $short_description, $description){
$newsID = $_Get['newsID'];
$delete = $_Get['delete'];
if(isset($delete))
{
$sql = "DELETE FROM `News` WHERE newsID= :newsID";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':newsID', $_GET['newsID'], PDO::PARAM_INT);
$stmt->execute();
echo "WORKS";
}
else
{
echo "Papapapapa";
}
}
}
之后调用DeleteNews方法。
$object = new Delete();
$object->DeleteNews($title, $date, $short_description, $description);