我有問題與此代碼,不修改數據,查詢工作PHP MySQL的PDO功能不修改數據,查詢工作
<?php
$DB_host = "localhost";
$DB_user = "root";
$DB_pass = "";
$DB_name = "acp";
try {
$dbh = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
$dbh -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$news_id = isset($_POST['news_id']) ? $_POST['news_id'] : NULL;
$news_id = $_POST['news_id'];
$news_title = $_POST['news_title'];
$news_content = $_POST['news_content'];
// query
$sql = "UPDATE `news` SET `news_title`=?, `news_content`=? WHERE news_id=?";
$sth = $dbh -> prepare($sql);
$sth -> execute(array($news_title,$news_content,$news_id));
header('Location: ../news_admin.php');
}
catch(PDOException $e) {
echo $e->getMessage();
}
$dbh = null;
>
這裏是演示: http://213.146.54.224/pizzeria/ap/index.php 登錄/密碼:管理/ 123456 http://213.146.54.224/pizzeria/ap/news_admin.php
http://php.net/manual/en/function.error-reporting.php –
你應該已經發布,是HTML表單有了這個。可能未定義的索引通知。 –
@ Fred-ii-我添加了HTML表單 – phoenix