Title: Insert to Database from form submit
Last modified: August 20, 2016

---

# Insert to Database from form submit

 *  [eddy180](https://wordpress.org/support/users/eddy180/)
 * (@eddy180)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/insert-to-database-from-form-submit/)
 * Everytime I try to submit a form into the database with INSERT, I get an error:
   
   _Fatal error: Call to a member function prepare() on a non-object in /…/…/saveTemplate.
   php on line 17
 *     ```
       <?php	global $wpdb;
   
       	$field1 = $_POST['tmplName'];
   
       	$sql = $wpdb->prepare(
            "INSERT INTO 'wp_templates' ('templateName') values ",
             $field1);
   
       $wpdb->query($sql);
       ?>
       ```
   
 * Can you please help me?

Viewing 1 replies (of 1 total)

 *  [luckdragon](https://wordpress.org/support/users/luckdragon/)
 * (@luckdragon)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/insert-to-database-from-form-submit/#post-2785216)
 * wouldn’t it be easier to do:
 *     ```
       global $wpdb;
       $field = array();
       $field['templateName'] = $_POST['tmplName'];
       $sql = $wpdb->insert('wp_templates',$field);
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Insert to Database from form submit’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [luckdragon](https://wordpress.org/support/users/luckdragon/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/insert-to-database-from-form-submit/#post-2785216)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
