记录未更新

时间:2013-06-14 07:21:09

标签: php mysql sql

我已经尝试了很多来解决这个小问题......我正在尝试更新PHPmyadmin数据库中的记录。

$query = 'UPDATE movie SET 
                    movie_name = "'.$_POST['movie_name'].'";
                    movie_year = '.$_POST['movie_year'].';
                    movie_type =   "'.$_POST['movie_type'].'";
                    movie_leadactor =  "'.$_POST['movie_leadactor'].'";
                    movie_director =  "'.$_POST['movie_director'].'";
                    movie_running_time = "'.$_POST['movie_time'].'";
                    movie_cost = "'.$_POST['movie_cost'].'";
                    movie_takings = "'.$_POST['movie_earn'].'"';

但是当我在sql中放入此查询时,它显示错误。

这是我的简单查询.....

UPDATE movie SET movie_name = "XXX"; movie_year = 2010; movie_type = "7"; movie_leadactor = "4"; movie_director = "6"; movie_running_time = "90 "; movie_cost = "6.0 "; movie_takings = "22.0 "

enter image description here

我该如何解决?请帮忙

错误发生在movie_year上。错误代码是1064

4 个答案:

答案 0 :(得分:3)

为什么你使用'; '而不是''分隔符....用逗号分隔符''修改如下

$query = 'UPDATE movie SET 
                movie_name = "'.$_POST['movie_name'].'",
                movie_year = '.$_POST['movie_year'].',
                movie_type =   "'.$_POST['movie_type'].'",
                movie_leadactor =  "'.$_POST['movie_leadactor'].'",
                movie_director =  "'.$_POST['movie_director'].'",
                movie_running_time = "'.$_POST['movie_time'].'",
                movie_cost = "'.$_POST['movie_cost'].'",
                movie_takings = "'.$_POST['movie_earn'].'"';

并尝试使用' mysql_real_escape_string '来逃避帖子值

答案 1 :(得分:3)

在每行末尾使用,代替;

UPDATE movie 
SET movie_name = "XXX", 
movie_year = 2010,
...

答案 2 :(得分:1)

你错过了逗号部分

$query = 'UPDATE movie SET 
                    movie_name = "'.$_POST['movie_name'].',";
                    movie_year = '.$_POST['movie_year'].',;
                    movie_type =   "'.$_POST['movie_type'].',";
                    movie_leadactor =  "'.$_POST['movie_leadactor'].',";
                    movie_director =  "'.$_POST['movie_director'].',";
                    movie_running_time = "'.$_POST['movie_time'].',";
                    movie_cost = "'.$_POST['movie_cost'].',";
                    movie_takings = "'.$_POST['movie_earn'].'"';

答案 3 :(得分:0)

试试这个:

$movie_name=$_POST['movie_name'];
$movie_year=$_POST['movie_year'];
$movie_type=$_POST['movie_type'];
$movie_leadactor=$_POST['movie_leadactor'];
$movie_director=$_POST['movie_director'];
$movie_time=$_POST['movie_time'];
$movie_cost=$_POST['movie_cost'];
$movie_earn=$_POST['movie_earn'];

$query = "UPDATE movie SET movie_name ='$movie_name', movie_year = '$movie_year', movie_type ='$movie_type', movie_leadactor ='$movie_leadactor', movie_director ='$movie_director', movie_running_time ='$movie_time', movie_cost ='$movie_cost', movie_takings ='$movie_earn'";

并添加此项以检查错误:

if (!mysql_query($query))
    {
        die('Error: ' . mysql_error());
    }

这应该完美无缺。