表单值不起作用的SQL Update

时间:2015-09-21 16:45:25

标签: php mysql sql forms

我尝试使用表单值更新表,尽管它似乎没有在数据库中更新,也没有错误。

<?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'");

?>

1 个答案:

答案 0 :(得分:0)

确保从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();