php - I am getting an error when inserting with execute($array) -


i have table

percentile      int(3)  no            fosw            int(3)  yes     null      dflr            int(3)  yes     null      foa             int(3)  yes     null      sog             int(3)  yes     null      rst             int(3)  yes     null      ssw             int(3)  yes     null     total           int(3)  no   

and array:

array (     [percentile] => 99     [fosw] => 125     [dflr] => 110     [foa] => 60     [sog] => 120     [rst] => 40     [ssw] => 45     [total] => 500 ) 

and code not work reason... catch not throw error. if statement echos error...

if ($_post['percent']=='add'){     try{         $post = $_post;         unset($post['percent']);          $sth = $dbh->prepare("insert percentiles (percentile, fosw, dflr, foa, sog, rst, ssw, total) values (?,?,?,?,?,?,?,?)");          if ($sth->execute($post)){             echo 'done<br/>';         }          else echo 'error';     }      catch(pdoexception $e){         echo 'error'.$e;     } } 

your array $post matches 8 values required insert operation, array should indexed integers , not associative array/dictionary.

array (     [percentile] => 99     [fosw] => 125     [dflr] => 110     [foa] => 60     [sog] => 120     [rst] => 40     [ssw] => 45     [total] => 500 ) 

the above array work if change prepare() call follows:

$sth = $dbh->prepare("insert percentiles          (percentile, fosw,          dflr, foa,          sog, rst,          ssw, total)      values         (:percentile, :fosw,          :dflr, :foa,          :sog, :rst,          :ssw, :total)"); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -