title: No data supplied for parameters in MySQLi prepared statement
body: <p>I've been reworking my website from unprotected MySQL queries to mysqli prepared statements and it all went well until I got this: No data supplied for parameters in prepared statement.</p>
  <pre><code>if(empty($err)) {
      $pSETQuery  = NULL;
      if(!empty($_POST['password'])) {
          $pSETQuery .= &quot;, password = ?&quot;;
      }
      if($session-&gt;isSuperuser()) {
          $pSETQuery .= &quot;, usertype = ?&quot;;
      }
      if(!($stmt = $database-&gt;prepare(&quot;UPDATE user SET username = ?, email = ? $pSETQuery WHERE UserId = ?&quot;))) {
          $err[] = &quot;PREPARE FAILED.&quot;;
      }
      $stmt-&gt;bind_param(&quot;s&quot;, $_POST['username']);
      $stmt-&gt;bind_param(&quot;s&quot;, $_POST['email']);
      if(!empty($_POST['password'])) {
          $stmt-&gt;bind_param(&quot;s&quot;, $_POST['password']);
      }
      if($session-&gt;isSuperuser()) {
          $stmt-&gt;bind_param(&quot;s&quot;, $_POST['usertype']);
      }
      $stmt-&gt;bind_param(&quot;i&quot;, $_POST['userid']);
      if(!$stmt-&gt;execute()){
          $err[] = &quot;Execute failed. ERROR: &quot; . $stmt-&gt;error;
      }
  
  }
  </code></pre>