Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- function db_insert($table, $array = array()) {
- global $con;
- foreach ($array as $field => $value) {
- $fields[] = $field;
- $values[] = $con->real_escape_string($value);
- }
- $sql = "INSERT INTO {$table} (`" . implode("`,`", $fields) , "`) VALUES ('" . implode("','", $values) . "')";
- if ($con->query($sql)) {
- return true;
- }
- return false;
- }
- // HOW TO USE:
- $array = array(
- 'column1' => 'value1',
- 'column2' => 123,
- 'column3' => 'value3'
- )
- db_insert('table_name', $array);
Add Comment
Please, Sign In to add comment