-4

我有简单的代码,我一直在其他文件中使用类似的模板,但似乎我无法使这个工作(问题是第一个 $sqlCommand 执行得很好,之后任何其他都不起作用。 .即使用一些简单的sql语句替换了其余代码(在第一个$sqlCommand之后),表也没有更新(与任何其他表相同)。授予所有特权。我只是不知道出了什么问题在这里...提前感谢您的帮助

<?php
$con = mysqli_connect("localhost","root","","moviegallary")
       or die('Could not connect: '. mysqli_connect_error());
$sqlCommand = "update movie set title='$_GET[title2]', category='$_GET[category2]',   movieDesc='".mysql_real_escape_string($_GET['moviedesc2'])."',image='".mysql_real_escape_st ring($_GET['poster2'])."' where movieCode=$_GET[moviecode2];";

if (!mysqli_query($con,$sqlCommand))
{
    die ('Error: '.mysqli_error($con));
}
echo '<h1>1 record in "movie" table updated</h1>';

foreach ($_GET['new_star'] as $new_star)
{
    $query = mysqli_query($con,"select * from artist where concat(firstName,' ', lastName)='$new_star'");
    $count=mysqli_num_rows($query);
    if ($count>0) {
        $sqlCommand="insert into role select  $_GET[moviecode2], artistID from artist where concat(firstName,' ', lastName)='$new_star ;";
        echo '<h1>1 record in "role" table is inserted</h1>';
    }
}

mysqli_close($con);
?>
4

1 回答 1

4

您没有执行该INSERT语句。

mysqli_query($con, $sqlCommand);

您需要开始使用准备好的语句,因为您的代码容易受到 SQL 注入的影响。

于 2013-05-22T15:46:47.017 回答