title: Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
body: <p>Hello guys i try to solve this problem for days but without results can you pls help me? 
  here is all problem:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\dashboard\sn\classes\DB.php:12 Stack trace: #0 C:\xampp\htdocs\dashboard\sn\classes\DB.php(12): PDOStatement->execute(Array) #1 C:\xampp\htdocs\dashboard\sn\classes\Post.php(24): DB::query('INSERT INTO pos...', Array) #2 C:\xampp\htdocs\dashboard\sn\profile.php(54): Post::createImgPost('', '1', '1') #3 {main} thrown in C:\xampp\htdocs\dashboard\sn\classes\DB.php on line 12</p>
  </blockquote>
  
  <p>here is Post.php file: </p>
  
  <pre><code>&lt;?php
  
  class Post {
          public static function createPost($postbody, $loggedInUserId, $profileUserId) {
  
                  if (strlen($postbody) &gt; 160 || (strlen($postbody) &lt; 1)) {
                          die('Incorrect lenght!');
                  }
  
                  $topics = self::getTopics($postbody);
  
                  if ($loggedInUserId == $profileUserId) {
                          DB::query('INSERT INTO posts VALUES (:id, :postbody, NOW(), :userid, 0, \'\', :topics)', array(':id'=&gt;0, ':postbody'=&gt;$postbody, ':userid'=&gt;$profileUserId, ':topics'=&gt;$topics));
                  } else {
                          die('Incorrect user!');
                  }
          }
  
          public static function createImgPost($postbody, $loggedInUserId, $profileUserId) {
                  if (strlen($postbody) &gt; 160) {
                          die('Incorrect length!');
                  }
                  $topics = self::getTopics($postbody);
                  if ($loggedInUserId == $profileUserId) {
                          DB::query('INSERT INTO posts VALUES (\'\', :postbody, NOW(), :userid, 0, \'\', \'\')', array(':postbody'=&gt;$postbody, ':userid'=&gt;$profileUserId, ':topics'=&gt;$topics));
                          $postid = DB::query('SELECT id FROM posts WHERE user_id=:userid ORDER BY ID DESC LIMIT 1;', array(':userid'=&gt;$loggedInUserId))[0]['id'];
                          return $postid;
                  } else {
                    die('Incorrect user!');
                  }
            }
  
          public static function likePost($postId, $likerId) {
                  if (!DB::query('SELECT user_id FROM post_likes WHERE post_id=:postid and user_id=:userid', array(':postid'=&gt;$postId, ':userid'=&gt;$likerId))) {
                          DB::query('UPDATE posts SET likes=likes+1 WHERE id=:postid', array(':postid'=&gt;$postId));
                          DB::query('INSERT INTO post_likes VALUES(:id, :postid, :userid)', array(':id'=&gt;0, ':postid'=&gt;$postId, ':userid'=&gt;$likerId));
                  } else {
                          DB::query('UPDATE posts SET likes=likes-1 WHERE id=:postid', array(':postid'=&gt;$postId));
                          DB::query('DELETE FROM post_likes WHERE post_id=:postid AND user_id=:userid', array(':postid'=&gt;$postId, ':userid'=&gt;$likerId));
                  }
          }
  
          public static function link_add($text) {
  
                          $text = explode(" ", $text);
                          $newstring = "";
  
                          foreach ($text as $word) {
                                if (substr($word, 0, 1) == "@") {
                                        $newstring .= "&lt;a href='profile.php?username=".substr($word, 1)."'&gt;".htmlspecialchars($word)."&lt;/a&gt;";
                                } else if (substr($word, 0, 1) == "#") {
                                        $newstring .= "&lt;a href='topics.php?topic=".substr($word, 1)."'&gt;".htmlspecialchars($word)."&lt;/a&gt;";
                                } else {
                                        $newstring .= htmlspecialchars($word)." ";
                                }
                          }
  
                          return $newstring;
          }
          public static function getTopics($text) {
  
                          $text = explode(" ", $text);
                          $topics = "";
  
                          foreach ($text as $word) {
                                if (substr($word, 0, 1) == "#") {
                                        $topics .= substr($word, 1).",";
                                }
                          }
  
                          return $topics;
          }
  
          public static function displayPosts($userid, $username, $loggedInUserId) {
                          $dbposts = DB::query('SELECT * FROM posts WHERE user_id=:userid ORDER BY id DESC', array(':userid'=&gt;$userid));
                          $posts = "";
                          foreach($dbposts as $p) {
  
                                  if (!DB::query('SELECT post_id FROM post_likes WHERE post_id=:postid AND user_id=:userid', array(':postid'=&gt;$p['id'], ':userid'=&gt;$loggedInUserId))) {
  
                                          $posts .= "&lt;img src='".$p['postimg']."'&gt;".self::link_add($p['body'])."
                                          &lt;form action='profile.php?username=$username&amp;postid=".$p['id']."' method='post'&gt;
                                                &lt;input type='submit' name='like' value='Like'&gt;
                                                &lt;span&gt;".$p['likes']." likes&lt;/span&gt;
                                          &lt;/form&gt;
                                          &lt;hr /&gt;&lt;/br /&gt;
                                          ";
                                  } else {
                                          $posts .= "&lt;img src='".$p['postimg']."'&gt;".self::link_add($p['body'])."
                                          &lt;form action='profile.php?username=$username&amp;postid=".$p['id']."' method='post'&gt;
                                                &lt;input type='submit' name='unlike' value='Unlike'&gt;
                                                &lt;span&gt;".$p['likes']." likes&lt;/span&gt;
                                          &lt;/form&gt;
                                          &lt;hr /&gt;&lt;/br /&gt;
                                          ";
                                  }
                          }
                          return $posts;
          }
     }
  
     ?&gt;
  </code></pre>
  
  <p>and here is profile.php file:</p>
  
  <pre><code>&lt;?php
  include('./classes/DB.php');
  include('./classes/Login.php');
  include('./classes/Post.php');
  include('./classes/Image.php');
  $username = "";
  $verified = False;
  $isFollowing = False;
  if (isset($_GET['username'])) {
            if (DB::query('SELECT username FROM users WHERE username=:username', array(':username'=&gt;$_GET['username']))) {
                    $username = DB::query('SELECT username FROM users WHERE username=:username', array(':username'=&gt;$_GET['username']))[0]['username'];
                    $userid = DB::query('SELECT id FROM users WHERE username=:username', array(':username'=&gt;$_GET['username']))[0]['id'];
                    $verified = DB::query('SELECT verified FROM users WHERE username=:username', array(':username'=&gt;$_GET['username']))[0]['verified'];
                    $followerid = Login::isLoggedIn();
                    if (isset($_POST['follow'])) {
                            if ($userid != $followerid) {
                                    if (!DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=&gt;$userid, ':followerid'=&gt;$followerid))) {
                                            if ($followerid == 6) {
                                                    DB::query('UPDATE users SET verified=1 WHERE id=:userid', array(':userid'=&gt;$userid));
                                            }
                                            DB::query('INSERT INTO followers VALUES (:id, :userid, :followerid)', array(':id'=&gt;0, ':userid'=&gt;$userid, ':followerid'=&gt;$followerid));
                                            } else {
                                              echo 'Already following!';
                                            }
                                    $isFollowing = True;
                            }
                    }
                    if (isset($_POST['unfollow'])) {
                            if ($userid != $followerid) {
                                    if (DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=&gt;$userid, ':followerid'=&gt;$followerid))) {
                                            if ($followerid == 6) {
                                                    DB::query('UPDATE users SET verified=0 WHERE id=:userid', array(':userid'=&gt;$userid));
                                            }
                                            DB::query('DELETE FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=&gt;$userid, ':followerid'=&gt;$followerid));
                                    }
                            $isFollowing = False;
                            }
                    }
                    if (DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=&gt;$userid, ':followerid'=&gt;$followerid))) {
                            //echo 'Already following!';
                            $isFollowing = True;
                    }
                    if (isset($_POST['deletepost'])) {
                            if (DB::query('SELECT id FROM posts WHERE id=:postid AND user_id=:userid', array(':postid'=&gt;$_GET['postid'], ':userid'=&gt;$followerid))) {
                                    DB::query('DELETE FROM posts WHERE id=:postid and user_id=:userid', array(':postid'=&gt;$_GET['postid'], ':userid'=&gt;$followerid));
                                    DB::query('DELETE FROM post_likes WHERE post_id=:postid', array(':postid'=&gt;$_GET['postid']));
                                    echo 'Post deleted!';
                            }
                    }
                    if (isset($_POST['post'])) {
                            if ($_FILES['postimg']['size'] == 0) {
                                    Post::createPost($_POST['postbody'], Login::isLoggedIn(), $userid);
                            } else {
                                    $postid = Post::createImgPost($_POST['postbody'], Login::isLoggedIn(), $userid);
                                    Image::uploadImage('postimg', "UPDATE posts SET postimg=:postimg WHERE id=:postid", array(':postid'=&gt;$postid));
                            }
                    }
                    if (isset($_GET['postid']) &amp;&amp; !isset($_POST['deletepost'])) {
                            Post::likePost($_GET['postid'], $followerid);
                    }
                    $posts = Post::displayPosts($userid, $username, $followerid);
      } else {
              die('User not found!');
      }
    }
    ?&gt;
      &lt;h1&gt;&lt;?php echo $username; ?&gt;'s Profile&lt;?php if ($verified) { echo  - 
      Verified';` } ?&gt;&lt;/h1&gt;
      &lt;form action="profile.php?username=&lt;?php echo $username; ?&gt;" 
      method="post"&gt;
      &lt;?php
      if ($userid != $followerid) {
              if ($isFollowing) {
                      echo '&lt;input type="submit" name="unfollow" 
         value="Unfollow"&gt;';
              } else {
                      echo '&lt;input type="submit" name="follow" value="Follow"&gt;';
              }
      }
      ?&gt;
  &lt;/form&gt;
  
  &lt;form action="profile.php?username=&lt;?php echo $username; ?&gt;" method="post" 
  enctype="multipart/form-data"&gt;
      &lt;textarea name="postbody" rows="8" cols="80"&gt;&lt;/textarea&gt;
      &lt;br /&gt;Upload an image:
      &lt;input type="file" name="postimg"&gt;
      &lt;input type="submit" name="post" value="Post"&gt;
   &lt;/form&gt;
  
   &lt;div class="posts"&gt;
      &lt;?php echo $posts; ?&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>almost every function works fine only here is some problem DB should be configured right too </p>
  
  <p>probably there is problem with this query but idk where:</p>
  
  <pre><code>                        DB::query('INSERT INTO posts VALUES (\'\', :postbody, NOW(), :userid, 0, \'\', \'\')', array(':postbody'=&gt;$postbody, ':userid'=&gt;$profileUserId, ':topics'=&gt;$topics));
  </code></pre>
  
  <p>thank you for your time and energy</p>