title: Error in PDO Update Function
body: <pre><code>$table="menu_permission";
  $field = array('permission'=&gt;$mnuprmis);
  $ob-&gt;update($table,$field,'staff_id',$stfid);
  
  
  public function update($table, $fields, $wherefield, $wherefieldvalues) 
      {
          $sql = "update $table set";
          foreach ( $fields as $fieldname =&gt; $sfieldvalue )
              $sql .=  $fieldname."= '".$sfieldvalue."',";
              $sql = substr($fldquery,0,strlen($fldquery)-1);
              $sql .=" where $wherefield = '$wherefieldvalues'";
          $q = $this-&gt;conn-&gt;prepare($sql);
          $q-&gt;execute();
          return true;
      }
  </code></pre>
  
  <p>The error</p>
  
  <pre><code>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: 
  Syntax error or access violation: 1064 You have an error in your SQL syntax; 
  check the manual that corresponds to your MySQL server version for the right syntax to use 
  near 'where staff_id = '1'' at line 1' 
  in G:\xampp\htdocs\live\Billing Suryas\model\DBConfig.php:171 
  Stack trace: #0 G:\xampp\htdocs\live\Billing Suryas\model\DBConfig.php(171): PDOStatement-&gt;execute() 
  #1 G:\xampp\htdocs\live\Billing Suryas\pages\permission_pages.php(257): Connection-&gt;update('menu_permission', Array, 'staff_id', '1') 
  #2 {main} thrown in G:\xampp\htdocs\live\Billing Suryas\model\DBConfig.php on line 171
  </code></pre>