title: update failing using PDO with mysql
body: <p>insert select and delete are all working but my update is failing.  I first select a single record into a form, the values from that record are populating the form, so far so good.  However when I send the form I get the following error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught ArgumentCountError: Too few arguments to
    function Blog::updateBlogPost(), 0 passed in
    /Applications/XAMPP/xamppfiles/htdocs/TravelClub/members/editPost.php
    on line 91 and exactly 2 expected in
    /Applications/XAMPP/xamppfiles/htdocs/TravelClub/Blog.Class.php:124
    Stack trace: #0
    /Applications/XAMPP/xamppfiles/htdocs/TravelClub/members/editPost.php(91):
    Blog->updateBlogPost() #1
    /Applications/XAMPP/xamppfiles/htdocs/TravelClub/members/editPost.php(25):
    processForm() #2 {main} thrown in
    /Applications/XAMPP/xamppfiles/htdocs/TravelClub/Blog.Class.php on
    line 124</p>
  </blockquote>
  
  <p>The PDO statement in my blog class is as follows:</p>
  
  <pre><code>// update record from form data
      public function updateBlogPost($postid, $body)
      {
          $conn = parent::connect();
          $sql = "UPDATE blog set body = :body where postid = :postid";
          echo $sql;
          try {
              $st = $conn-&gt;prepare($sql);
              $st-&gt;bindValue(":postid", $postid, PDO::PARAM_STR);
              $st-&gt;bindValue(":body", $body, PDO::PARAM_STR);
              $st-&gt;execute();
              parent::disconnect($conn);
          } catch (PDOException $e) {
              parent::disconnect($conn);
              die("Query failed: " . $e-&gt;getMessage());
          }
      }
  </code></pre>
  
  <p>and the php script which creates the form and handles the script is:</p>
  
  <pre><code>&lt;?php
  require_once( "../common.inc.php" );
  
  
  
  checkLogin();
  // show nav bar for members area
  displayNavBar();
  
  $postid = isset( $_GET["postid"] ) ? (string)$_GET["postid"] : 0;
  $body = isset( $_GET["body"]) ? (string)$_GET["body"] :0;
  //$post = Blog::viewBlogPost($postid );
  //$body = Blog::viewBlogPost($body );
  
  echo "&lt;br&gt;";
  echo "the post id is " .$postid;
  echo "&lt;br&gt;";
  echo "the blog text is " . $body;
  
  
  // if the form action is register add user or handle errors
  if ( isset( $_POST["action"] ) and $_POST["action"] == "updateBlogPost" ) {
      $postid = isset( $_GET["postid"] ) ? (int)$_GET["postid"] : 0;
      $body = isset( $_GET["body"] ) ? (int)$_GET["body"] : 0;
      processForm();
  } else {
      displayForm( array(), array(), new Blog( array() ) );
  }
  
  
  // if there are no errors display the form
  function displayForm( $errorMessages, $missingFields, $blog ) {
      displayPageHeader( "Edit your blog post" );
  
      if ( $errorMessages ) {
          foreach ( $errorMessages as $errorMessage ) {
              echo $errorMessage;
          }
      } else {
          ?&gt;
      &lt;?php } ?&gt;
  
  
      &lt;form action="editPost.php" method="post" style="margin-bottom: 50px;"&gt;
          &lt;div style="width: 30em;"&gt;
              &lt;input name="action" type="hidden" value="updateBlogPost"&gt;
              &lt;!--&lt;label for="userid"&lt;?php validateField( "postid", $missingFields ) ?&gt;&gt;user id&lt;/label&gt;--&gt;
              &lt;input type="hidden" id="postid" cols="50" name="postid" rows="4" value="&lt;?php echo $blog-&gt;getValueEncoded( "postid" ) ?&gt;; ?&gt;"&gt;&lt;?php echo $blog-&gt;getValueEncoded( "postid" ) ?&gt;
              &lt;input type="hidden" id="body" cols="50" name="body" rows="4" value="&lt;?php echo $blog-&gt;getValueEncoded( "body" ) ?&gt;; ?&gt;"&gt;&lt;?php echo $blog-&gt;getValueEncoded( "body" ) ?&gt;
             &lt;input type="text" value="&lt;?php echo htmlspecialchars($_GET['postid']); ?&gt;"&gt;
              &lt;div style="clear: both;"&gt;
                  &lt;label for="body"&lt;?php validateField( "body", $missingFields ) ?&gt;&gt;&lt;?php echo $blog-&gt;getValueEncoded( "body" ) ?&gt;&lt;/label&gt;
  
                  &lt;textarea id="body" cols="50" name="body" rows="4" value="&lt;?php echo htmlspecialchars($_GET['body']); ?&gt;"&gt;&lt;?php echo htmlspecialchars($_GET['body']); ?&gt;&lt;/textarea&gt;
                  &lt;div style="clear: both;"&gt;
                      &lt;input id="submitButton" name="submitButton" type="submit" value="Send Details"&gt;
                      &lt;input id="resetButton" name="resetButton" style="margin-right: 20px;" type="reset" value="Reset Form"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
      &lt;/form&gt;
      &lt;?php
      displayPageFooter();
  }
  
  //  process the form data and store it in the database
  function processForm() {
  
  
      $requiredFields = array( "postid", "body" );
      $missingFields = array();
      $errorMessages = array();
      $blog = new blog( array(
          "postid" =&gt; isset( $_POST["postid"] ) ? preg_replace( "/[^ \-\_a-zA-Z0-9]/", "", $_POST["postid"] ) : "",
          "body" =&gt; isset( $_POST["body"] ) ? preg_replace( "/[^ \-\_a-zA-Z0-9]/", "", $_POST["body"] ) : "",
          "postdate" =&gt;  date( "Y-m-d H:i:s" )
  
      ) );
      foreach ( $requiredFields as $requiredField ) {
          if ( !$blog-&gt;getValue( $requiredField ) ) {
              $missingFields[] = $requiredField;
          }
      }
      // deal with errors
      if ( $missingFields ) {
          $errorMessages[] = '&lt;p class="error"&gt;There were some missing fields in the form you submitted. Please complete the fields highlighted below and click Send Details to resend the form.&lt;/p&gt;';
      }
  
      if ( $errorMessages ) {
          displayForm( $errorMessages, $missingFields, $blog );
      } else {
          $blog-&gt;updateBlogPost();
          displayThanks();
      }
  }
  
  // when the values are stored, display a thankyou page
  function displayThanks() {
  
      displayPageHeader( "Your post has been updated" );
      ?&gt;
      &lt;p&gt;Thank you, your blog post has been updated.&lt;/p&gt;
  
      &lt;a href="blog.php"&gt;go to blog page&lt;/a&gt;
      &lt;?php
      displayPageFooter();
  }
  ?&gt;
  </code></pre>
  
  <p>Ive tried adding the two varibles to this line:</p>
  
  <pre><code>$blog-&gt;updateBlogPost();
  </code></pre>
  
  <p>i.e. </p>
  
  <pre><code>$blog-&gt;updateBlogPost($postid, $body);
  </code></pre>
  
  <p>it then says these are undefined, even if I add the declarations to that particular routine the record doesn't update.</p>
  
  <p>I've been stuck on this for a couple of days now and any help would be greatly appreciated.</p>