/ Published in: PHP
Simple method to insert data to sql
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Build the field:value array $in['fieldname'] = 'Value'; $in['fieldname2'] = 'Value 2'; // Insert into db $db->insert('tablename', $in); // Method: public function insert($table, $data) { $SQL = "INSERT INTO `{$table}` ({$fieldnames}) VALUES ({$fieldvalues})"; $sth = $this->prepare($SQL); return $sth->execute($data); }