php - Why is this SQL processing twice? -


basically, reason sql insert query processing twice , i'm not sure why.

here's form :

<form class="form-horizontal" method="post" action="">     <input id="email" name="email" class="text-style" type="email">     <input id="password" name="password" class="text-style" type="password">     <input id="secret" name="secret" class="text-style" type="text">     <select class="text-style" id="console" name="console">         <option value="xbox">xbox 360</option>         <option value="ps3">ps3</option>     </select>     <select class="text-style" id="status" name="status">         <option value="0">disabled</option>         <option value="1">enabled</option>     </select>     <button class="btn btn-success pull-right" name="add_account">add account</button> </form> 

here's php process form :

if(isset($_post['add_account'])) {     $data = array(         'email' => base64_encode($_post['email']),         'password' => base64_encode($_post['password']),         'secret' => base64_encode($_post['secret']),         'console' => $_post['console'],         'status' => $_post['status'],         'date_added' => date("y-m-d h:i:s"),         'last_check' => date("y-m-d h:i:s")     );     $result = $db->insert('accounts',$data);     if($result) {         if(!in_array("account added successfully.", $msgs))             array_push($msgs,"account added successfully.");     } else {         array_push($msgs,"^failed add account.");     } } 

and here's $db->insert function

public function insert($table=null,$array_of_values=array()) {     if ($table===null || empty($array_of_values) || !is_array($array_of_values)) return false;     $fields=array(); $values=array();     foreach ($array_of_values $id => $value) {         $fields[]=$id;         if (is_array($value) && !empty($value[0])) $values[]=$value[0];         else $values[]="'".mysql_real_escape_string($value,$this->connection)."'";     }     $s = "insert $table (".implode(',',$fields).') values ('.implode(',',$values).')';     if ($this->runsql($s)) return true;     return false; } 

and here's runsql function :

public function runsql($sqlquery,$possibleerror = 0) {     if($sqlquery=="") {return false;}     mysql_query($sqlquery);     if(mysql_error()){           return false;     }     return true; } 

your code looks good, , there doesn't seem chance insert happen twice. can install firebug firefox, , right-click form -> " inspect element ". go "net" , see form posts, , if posts once? maybe there javascript attempting submit form again?

if looks good, db insert function should looked at:


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -