title: Failed to run query: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
body: <p>I have a problem here. I keep getting this error which is number of bound variables does not match number of tokens. I double check my code and doesn't seems to have an error on it. Anyway, I am new to these PDO thing.</p>
  
  <p>This is the code how I call the data from database to echo in the form</p>
  
  <pre><code>if(isset($_GET['idstudent'], $_GET['idbook'])){
  $_SESSION['link']=$_GET['idstudent'];
  $_SESSION['link2']=$_GET['idbook'];
  $sessionidstudent = $_SESSION['link'];
  $sessionidbook = $_SESSION['link2']; }  
  
  
  $query = " 
      SELECT 
          * 
      FROM viewlibrary
      WHERE 
          id = :sessionidstudent AND
          serialno = :sessionidbook
  
  "; 
  
  $query_params = array( 
      ':sessionidstudent' =&gt; $_SESSION['link'],
      ':sessionidbook' =&gt; $_SESSION['link2'] 
  ); 
  
  try 
  { 
      $stmt = $db-&gt;prepare($query); 
      $result = $stmt-&gt;execute($query_params); 
  }
  catch(PDOException $ex) 
  { 
      die("Failed to run query: " . $ex-&gt;getMessage()); 
  }
  $r=$stmt-&gt;fetch(PDO::FETCH_ASSOC);    ?&gt;
  </code></pre>
  
  <p>This is my HTML code</p>
  
  <pre><code>&lt;form action="editpage.php" method="post" class="login, reminder"&gt;
  &lt;p&gt;Student Matric Number:
      &lt;input type="text" class="login-input" name="addmatricno" id="addmatricno" value="&lt;?php echo $r['matricno'] ?&gt;" placeholder="Enter student matric number"&gt;
      Student Name:
      &lt;input type="text" class="login-input" name="addname" id="addname" value="&lt;?php echo $r['studentname'] ?&gt;" placeholder="Enter student name"&gt;
      Programme:
      &lt;input type="text" class="login-input" name="addprogramme" id="addprogramme" value="&lt;?php echo $r['programme'] ?&gt;" placeholder="Enter student programme"&gt;
      Education Level:
  
      &lt;?php
  
          if($r['education_level'] == "PHD"){
              echo '&lt;select name="selectedulevel" id="selectedulevel" class="login-input"&gt;';
              echo '&lt;option disabled&gt;Please select education level&lt;/option&gt;';
              echo '&lt;option value="PHD" selected&gt;PHD&lt;/option&gt;';
              echo '&lt;option value="MASTER"&gt;MASTER&lt;/option&gt;';
              echo '&lt;option value="PHD"&gt;DEGREE&lt;/option&gt;&lt;/p&gt;&lt;/select&gt;';
          }
          else if($r['education_level'] == "MASTER"){
              echo '&lt;select name="selectedulevel" id="selectedulevel" class="login-input"&gt;';
              echo '&lt;option disabled&gt;Please select education level&lt;/option&gt;';
              echo '&lt;option value="PHD"&gt;PHD&lt;/option&gt;';
              echo '&lt;option value="MASTER" selected&gt;MASTER&lt;/option&gt;';
              echo '&lt;option value="PHD"&gt;DEGREE&lt;/option&gt;&lt;/p&gt;&lt;/select&gt;';
          }
          else{
              echo '&lt;select name="selectedulevel" id="selectedulevel" class="login-input"&gt;';
              echo '&lt;option disabled&gt;Please select education level&lt;/option&gt;';
              echo '&lt;option value="PHD"&gt;PHD&lt;/option&gt;';
              echo '&lt;option value="MASTER"&gt;MASTER&lt;/option&gt;';
              echo '&lt;option value="PHD" selected&gt;DEGREE&lt;/option&gt;&lt;/p&gt;&lt;/select&gt;';
          }
  
      ?&gt;
      &lt;input type="submit" name="updatestudent" id="updatestudent" value="Update Student" class="login-submit" style = "width: 20%; text-align: center"&gt;
  </code></pre>
  
  <p>Last but not least, my query code.</p>
  
  <pre><code>$query = " 
          UPDATE student
              SET
                  matricno = :addmatricno,
                  studentname = :addname,
                  programme = :addprogramme,
                  education_level = :selectedulevel
              WHERE
                  id = :sessionidstudent
      "; 
  
      $query_params = array( 
          ':addmatricno' =&gt; $_POST['addmatricno'], 
          ':addname' =&gt; $_POST['addname'], 
          ':addprogramme' =&gt; $_POST['addprogramme'], 
          ':selectedulevel' =&gt; $_POST['selectedulevel']
      ); 
  
      try 
      { 
          // Execute the query to create the user 
          $stmt = $db-&gt;prepare($query); 
          //$stmt-&gt;bindValue(':sessionidstudent',$sessionidstudent);
          $result = $stmt-&gt;execute($query_params); 
      } 
      catch(PDOException $ex) 
      { 
          // Note: On a production website, you should not output $ex-&gt;getMessage(). 
          // It may provide an attacker with helpful information about your code.  
          die("Failed to run query: " . $ex-&gt;getMessage()); 
      }
  
  
      // This redirects the user back to the login page after they register 
      echo '&lt;script language="javascript"&gt;';
      echo 'alert("Info updated successful.")';
      echo '&lt;/script&gt;'; 
      header("Refresh: 0; updatebooks.php"); 
      die(); 
  </code></pre>
  
  <p>note: $db refer to <code>$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);</code> where I put on other file and i can sure my connection to database has no problem at all.
  I have check my code many times but still getting the same error. </p>