Title: $wpdb insert
Last modified: August 20, 2016

---

# $wpdb insert

 *  [redds013](https://wordpress.org/support/users/redds013/)
 * (@redds013)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/wpdb-insert-1/)
 * Hi I have been trying for days to get this working and I must be missing something,
 * I have a custom table called hotels in my database. I have created a form for
   all the hotels info.
 * Basically I want to be able to put the infomation from the form to the database.
 * this is what I have used so far.
 * $wpdb->query(“INSERT INTO hotels (name,address,contact, Price) VALUES (‘$hname’,‘
   $address’, ‘$hcontact’,’$hcost’)”);..
 * This is a pure php question but how do I get image links stored in the table 
   as well.
 * Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Chandan Kumar](https://wordpress.org/support/users/chandanonline4u/)
 * (@chandanonline4u)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/wpdb-insert-1/#post-3013092)
 * To insert form records use as wpdb->insert as follows:
 *     ```
       $wpdb->insert(
       	'table',
       	array(
       		'column1' => 'value1',
       		'column2' => 123
       	),
       	array(
       		'%s',
       		'%d'
       	)
       );
       ```
   
 * You can get the image link by using select query in $wpdb->get_results function.
 * For more reference: [http://codex.wordpress.org/Class_Reference/wpdb](http://codex.wordpress.org/Class_Reference/wpdb)
 *  Thread Starter [redds013](https://wordpress.org/support/users/redds013/)
 * (@redds013)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/wpdb-insert-1/#post-3013093)
 * Thanks I have tried it and it hasn’t worked.
 * this is my code
    <?php
 * if (isset($_POST[‘submiited’])){
 *  $hname= $_POST[‘name’];
    $haddress= $_POST[‘address’]; $hcontact= $_POST[‘contact’];
   $hcost= $_POST[‘cost’]; global $wpdb; $wpdb->insert(‘hotel’,array(‘name’ => ‘
   $hname’,’Price’ => $address),array(‘%s’,’%d’)); } ?>
 * I am not sure exatly why its not working, I don’t get errors but nothing inserts
   into the database.
 * Thanks
 *  [Chandan Kumar](https://wordpress.org/support/users/chandanonline4u/)
 * (@chandanonline4u)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/wpdb-insert-1/#post-3013097)
 * You are passing string in price field and marked price as digit in next array.
   please check this and make sure if you are including the wp_load.php in your 
   file as follows:
 *     ```
       require_once('../../../wp-load.php');
       ```
   
 *  [chrispybacon](https://wordpress.org/support/users/chrispybacon/)
 * (@chrispybacon)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpdb-insert-1/#post-3013458)
 * Probably a bit late for this but you have a typo
 * $wpdb->insert(‘hotel’,array(‘name’ => ‘$hname’,’Price’ => $address),array(‘%s’,’%
   d’));
 * Should be haddress
 * $wpdb->insert(‘hotel’,array(‘name’ => ‘$hname’,’Price’ => $haddress),array(‘%
   s’,’%d’));
 * Probably worth turning on php errors

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘$wpdb insert’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 3 participants
 * Last reply from: [chrispybacon](https://wordpress.org/support/users/chrispybacon/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/wpdb-insert-1/#post-3013458)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
