jQuery移动mySQL - UPDATE不工作


jQuery mobile mySQL - UPDATE doesn't work

我的jquery移动应用程序有一个问题。
我正在尝试更新我的数据库中的一些东西,但它不起作用。我没有得到任何错误从JS或PHP文件(除非我打开update.php没有提交任何东西,但然后唯一的错误是未定义的索引值我绑定$_POST)。
最奇怪的是,INSERT INTO的相同代码实际上是有效的。

下面是工作代码:js:

$(document).ready(function(){
$("#saveForm").submit(function(){
    var formData=$(this).serialize();
    $.post('save.php',formData,processData).error(errorResponse);
    function processData(data){
        $("#popupSave").popup();
        $("#popupSave").popup("open");
    };
    function errorResponse(){
        alert("Something went wrong!");
    };
    return false; //Prevent the form from reloading
}); //end of submit function
}); //end of jquery document

php:

<?php
$dsn = "mysql:host=localhost;dbname=titlesdbs";
$username="root";
$password="";
try
{
$conn = new PDO($dsn, $username, $password);
echo 'Connected!';
}
catch(PDOException $error)
{
echo 'Connection no established: ' . $error->getMessage();
}
$sql="INSERT INTO titlestbl (title, pages, date) VALUES(:title, :pages, :date)";
try {
    $st=$conn->prepare($sql);
    $st->bindValue(':title', $_POST['title'], PDO::PARAM_STR);
    $st->bindValue(':pages', $_POST['pages'], PDO::PARAM_STR);
    $st->bindValue(':date', $_POST['date'], PDO::PARAM_STR);
    $st->execute();
}
catch (PDOException $e) {
echo "Server error - Try again".$e->getMessage();
};
$conn=null;
?>

和不起作用的代码:
js:

$(document).ready(function(){
$("#updateForm").submit(function(){
    var formData=$(this).serialize();
    $.post('update.php',formData,processData).error(errorResponse);
    function processData(data){
        $("#popupUpdate").popup();
        $("#popupUpdate").popup("open");
    };
    function errorResponse(){
        alert("Something went wrong!");
    };
    return false; //Prevent the form from reloading
}); //end of submit function
}); //end of jquery document

php:

<?php
$dsn = "mysql:host=localhost;dbname=titlesdbs";
$username="root";
$password="";
try
{
$conn = new PDO($dsn, $username, $password);
//echo 'Connected!';
}
catch(PDOException $error)
{
echo 'Connection no established: ' . $error->getMessage();
}
$sql="UPDATE titlestbl SET check=1, summary=':summary', quotes=':quotes', comments=':comments' WHERE id=:id";
try {
    $st=$conn->prepare($sql);
    $st->bindValue(':id', $_POST['id'], PDO::PARAM_STR);
    $st->bindValue(':summary', $_POST['summary'], PDO::PARAM_STR);
    $st->bindValue(':quotes', $_POST['quotes'], PDO::PARAM_STR);
    $st->bindValue(':comments', $_POST['comments'], PDO::PARAM_STR);
    $st->execute();
}
catch (PDOException $e) {
echo "Server error - Try again".$e->getMessage();
};
$conn=null;
?>

这是我找不到的愚蠢的错误还是我应该用另一种方式做?

在绑定变量周围有引号(' s),这会将它们转换为字符串字面量并中断您的更新。删除它们,你应该可以:

$sql = "UPDATE titlestbl SET check=1, summary=:summary, quotes=:quotes, comments=:comments WHERE id=:id";