Title: Insert data in wp_posts table
Last modified: August 19, 2016

---

# Insert data in wp_posts table

 *  [levani01](https://wordpress.org/support/users/levani01/)
 * (@levani01)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/insert-data-in-wp_posts-table/)
 * Hi
 * I’m trying to create custom write panel directly on my wordpress blog, without
   the dashbord. But I have a little problem. I use the standart INSERT statement
   to send data to database, but every time I do this only 0 is sent instead of 
   the real value. I have checked several times that the variable has right value
   but still no successes.
 * This is my code:
 * Form:
 *     ```
       <form id="lev-post" name="lev-post" method="post" action="?page_id=7">
       	<input name="lev-post-author-id" type="hidden" value="<?php echo $current_user->ID; ?>" />
       	<input name="lev-post-post-status" type="hidden" value="publish" />
       	<input name="lev-post-comment-status" type="hidden" value="open" />
       	<input name="lev-post-ping-status" type="hidden" value="open" />
       	<input name="lev-post-type" type="hidden" value="post" />
       	<input name="lev-post-menu-order" type="hidden" value="0" />
       	<input name="lev-post-post-parent" type="hidden" value="0" />
       	<input name="lev-post-post-cat" type="hidden" value="0" />
   
         <label>
         title: <input type="text" name="lev-post-title" />
         </label>
         <p>
           <label>
         content:  <textarea name="lev-post-content"></textarea>
           </label>
         </p>
         <p>
           <label>
         category:  <select name="lev-post-cat">
           <option value="1">Cat 1</option>
           <option value="2">Cat 2</option>
           <option value="3">Cat 3</option>
           <option value="4">Cat 4</option>
           </select>
           </label>
         </p>
         <input name="" type="submit" value="submit" />
       </form>
       ```
   
 * php code on page 7:
 *     ```
       <?php $lev_post_author_id = $_POST["lev-post-author-id"]; ?>
       <?php $lev_post_status = $_POST["lev-post-post-status"]; ?>
       <?php $lev_comment_status = $_POST["lev-post-comment-status"]; ?>
       <?php $lev_ping_status = $_POST["lev-post-ping-status"]; ?>
       <?php $lev_post_type = $_POST["lev-post-type"]; ?>
       <?php $lev_menu_order = $_POST["lev-post-menu-order"]; ?>
       <?php $lev_post_parent = $_POST["lev-post-post-parent"]; ?>
       <?php $lev_post_category = $_POST["lev-post-post-cat"]; ?>
       <?php $lev_post_title = $_POST["lev-post-title"]; ?>
       <?php $lev_post_content = $_POST["lev-post-content"]; ?>
       <?php $lev_post_cat = $_POST["lev-post-cat"]; ?>
   
       	<?php $table_name = 'wp_posts'; ?>
   
       <?php $insert = "INSERT INTO " . $table_name .
                   " (post_author, post_content, post_title, post_category, post_status, comment_status, ping_status, post_parent, menu_order, post_type) " .
                   "VALUES ('" . $current_user->ID . "',araperi,'" . $lev-post-title . "','" . $wpdb->escape($lev_post_category) . "','" . $wpdb->escape($lev_post_status) . "','" . $wpdb->escape($lev_comment_status) . "','" . $wpdb->escape($lev_ping_status) . "','" . $wpdb->escape($lev_post_parent) . "','" . $wpdb->escape($lev_menu_order) . "','" . $wpdb->escape($lev_post_type) . "')";
   
         $results = $wpdb->query( $insert ); ?>
       ```
   
 * Can anyone tell me what’s wrong with this code?
 * Thanks in advance

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

 *  Thread Starter [levani01](https://wordpress.org/support/users/levani01/)
 * (@levani01)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/insert-data-in-wp_posts-table/#post-1047251)
 * Any suggestions?
 *  [lacpapi](https://wordpress.org/support/users/lacpapi/)
 * (@lacpapi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/insert-data-in-wp_posts-table/#post-1047473)
 * Hi,
 * You don’t have a variable $current_user->ID.
 * <?php $lev_post_author_id = $_POST[“lev-post-author-id”]; ?>
 * you use $lev_post_author_id
 *  [lacpapi](https://wordpress.org/support/users/lacpapi/)
 * (@lacpapi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/insert-data-in-wp_posts-table/#post-1047474)
 * or $wpdb->escape()

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

The topic ‘Insert data in wp_posts table’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [lacpapi](https://wordpress.org/support/users/lacpapi/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/insert-data-in-wp_posts-table/#post-1047474)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
