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>

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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']
                        ) 
                );

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply