0

我已经尝试了很多来解决这个小问题......我正在尝试更新 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 "

在此处输入图像描述

我该如何解决?请帮忙

错误出现在movie_year 上。错误代码是 1064

4

4 回答 4

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 ”转义帖子值

于 2013-06-14T07:22:16.367 回答
3

在每行的末尾使用,而不是;

UPDATE movie 
SET movie_name = "XXX", 
movie_year = 2010,
...
于 2013-06-14T07:22:30.083 回答
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'].'"';
于 2013-06-14T07:23:36.777 回答
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());
    }

这应该可以完美地工作。

于 2013-06-14T07:34:40.613 回答