查询无效但未发生错误

时间:2014-09-16 18:34:41

标签: php mysql sql

我想用SQL更新SQL中的表,但它不会将PHP变量的值发送到表中......但是在页面上,根本没有错误,并且值都存储在变量中。我是PHP的新手。

这是我所做的代码:

    $query8 = "UPDATE contassessment SET test='$totTP', quiz='$totQP', asgmnt='$totAP', proj='$totPP' WHERE studID = '$stud";
    mysql_query($query8);

有人回答吗?

1 个答案:

答案 0 :(得分:1)

您在查询结尾处缺少报价:

$query8 = "UPDATE contassessment SET test='$totTP', quiz='$totQP', asgmnt='$totAP', proj='$totPP' WHERE studID = '$stud'";
mysql_query($query8);

您还应该考虑使用mysqli或PDO而不是mysql。此外,请确保清理您在数据库中输入的值。使用当前查询,您很容易受到SQL注入的攻击。<​​/ p>

要检查查询后是否发生错误,可以使用mysql_error:http://php.net/manual/en/function.mysql-error.php

但请确保使用mysqli或PDO,因为不推荐使用mysql。

相关问题