title: How do I get the previous record in database when I update?
body: <p>I have this history wherein I should put what I changed and the changed data. 
  For example: I updated apple to mango. In my history it should be Updated apple to mango. I've tried fetchColumn but it says Uncaught Error: Call to a member function fetchColumn(). Here is my code:</p>
  
  <pre><code>    if($_POST["operationproducts"] == "Edit")
   {
    $image = '';
    if($_FILES["image"]["name"] != '')
    {
     $image = upload_image();
    }
    else
    {
     $image = $_POST["hidden_image"];
    }
      //get previous name 
      $q= $connection-&gt;query("SELECT name FROM products WHERE prodID = :prodID");
       $previousname = $q-&gt;fetchColumn();
    $statement = $connection-&gt;prepare(
     "UPDATE products 
     SET categoryID = :categoryID, brandID = :brandID, name = :name, size = :size, image = :image, price = :price, stocks = :stocks, availability = :availability, description = :description
     WHERE prodID = :prodID
     "
    );
    $result = $statement-&gt;execute(
     array(
      ':categoryID' =&gt; $_POST["categoryID"],
      ':brandID' =&gt; $_POST["brandID"],
      ':name' =&gt; $_POST["name"],
      ':size' =&gt; $_POST["size"],
      ':image'  =&gt; $image,
      ':price' =&gt; $_POST["price"],
      ':stocks' =&gt; $_POST["stocks"],
      ':availability' =&gt; $_POST["availability"],
      ':description' =&gt; $_POST["description"],
      ':prodID'   =&gt; $_POST["prodID"]
     )
    );
    if(!empty($result))
    {
      //insert to product history
      $userid = $_SESSION['userid'];
      $previous = $previousname;
      $date = date("Y-m-d H:i:s");
      $action = 'Updated ' . $previous . 'to ' . $_POST["name"];
      $remarks = $_POST["remarks"];
      $statement = $connection-&gt;prepare("
                 INSERT INTO producthistory (userid, prodID, action, time, remarks) 
                 VALUES (:userid, :prodID, :action, :time, :remarks)
                ");
  
      $result = $statement-&gt;execute(
                 array(
                  ':userid' =&gt; $userid,
                  ':prodID' =&gt; $_POST["prodID"],
                  ':action' =&gt; $action,
                  ':time' =&gt; $date,
                  ':remarks'  =&gt; $remarks,
                 )
      );
      echo 'Data Updated';
    }
       }
  
   }
  </code></pre>