Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

php - Invalid parameter number: number of bound variables does not match number of tokens

I am getting this error message on an assignment for class. Ive created an UPDATE which uses forms for a user to edit the content being printed out from a database on the previous page.

I am getting Invalid parameter number: number of bound variables does not match number of tokens on line 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have five bound parameters but are only binding four values to them. You're missing your value for :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']
                        ) 
                );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...