我正在尝试使用表单值更新表,尽管它似乎未在数据库中更新并且也没有错误。
<?php
session_start();
if(!isset($_SESSION["user"]) or !is_array($_SESSION["user"]) or empty($_SESSION["user"])) {
// redirect to login page
}
$dbhost = "localhost";
$dbname = "***";
$dbuser = "***";
$dbpass = "***";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$date = date('Y-m-d') ."\n";
$now = time(); $utc_time = $now - intval(date('Z', $now));
$time = date('H:i:s', $now);
$pname = $_POST['pname'];
$pdetails = $_POST['pdetails'];
$pabout = $_POST['pabout'];
$pwebsite = $_POST['pwebsite'];
$pyoutube = $_POST['pyoutube'];
$pfacebook = $_POST['pfacebook'];
$uID = $_POST['uID'];
$id = $_POST['id'];
$seshID = $_SESSION['user']['id'];
$conn->prepare($sql = "UPDATE pages SET pname='$pname', pdetails='$pdetails', pabout='$pabout', pwebsite='$pwebsite', pyoutube='$pyoutube', pfacebook='$pfacebook' WHERE id='$id' AND author_id='$seshID'");
?>
最佳答案
确保您从POST方法获取所有数据。为此,您可以回显所有变量...脚本不起作用的根本原因是您没有将查询发送到数据库。
$stmt = $conn->prepare("UPDATE pages SET pname='$pname', pdetails='$pdetails', pabout='$pabout', pwebsite='$pwebsite', pyoutube='$pyoutube', pfacebook='$pfacebook' WHERE id='$id' AND author_id='$seshID'");
$stmt->execute();