参数号无效:绑定变量数与令牌数不匹配

时间:2014-05-02 00:18:27

标签: php html

我在课程作业上收到此错误消息。我创建了一个UPDATE,它使用表单供用户编辑从上一页的数据库中打印出来的内容。

我得到的参数号无效:绑定变量的数量与第14行的令牌数量不匹配

<?
require '../connection.php';
if (isset($_POST['save'])) {    
    $sql = "UPDATE videoinfo
            SET submitter = :submitter,
                videoTitle = :videoTitle,
                channelName = :channelName,
                videoLink = :videoLink
            WHERE videoId = :videoId";
    $stmt = $dataconn -> prepare($sql);
    $stmt -> execute( array(":submitter" => $_POST['submitter'],
                            ":videoTitle" => $_POST['videoTitle'],
                            ":channelName" => $_POST['channelName'],
                            ":videoLink" => $_POST['videoLink']) ); 

    echo "Record Updated";
    echo "<br />";
    include 'adminmain.php';
} else { 
$sql = "SELECT *
        FROM videoinfo AS v
        WHERE videoId = :videoId";      
$stmt = $dataconn -> prepare($sql);
$stmt -> execute( array(":videoId" => $_POST['videoId']) );
$video = $stmt->fetch();
}?>

<html>
<?
if (isset($_POST['update'])) {
?>

  <form method="post">
      Submitter: <input type="text" name="submitter" value="<?= $video['submitter'] ?>" /> <br />
      Video Title: <input type="text" name="videoTitle" value="<?= $video['videoTitle'] ?>" /> <br />
      Channel Name: <input type="text" name="channelName" value="<?= $video['channelName'] ?>" /> <br />
      Video Link: <input type="text" name="videoLink" value="<?= $video['videoLink'] ?>" /> <br />
      <input type="hidden" name="videoId" value="<?= $video['videoId'] ?>" />
      <input type="submit" value="Save" name="save" />  
  </form>

<?
  }//endIf
?>
</html>

1 个答案:

答案 0 :(得分:5)

您有五个绑定参数,但只绑定了四个值。您错过了:videoId的价值。

$sql = "UPDATE videoinfo
        SET submitter = :submitter,
            videoTitle = :videoTitle,
            channelName = :channelName,
            videoLink = :videoLink
        WHERE videoId = :videoId";
$stmt = $dataconn -> prepare($sql);
$stmt -> execute( array(":submitter" => $_POST['submitter'],
                        ":videoTitle" => $_POST['videoTitle'],
                        ":channelName" => $_POST['channelName'],
                        ":videoLink" => $_POST['videoLink'],
                        ":videoId" => $_POST['videoId']
                        ) 
                );