Title: HTML form to database using custom template
Last modified: August 22, 2016

---

# HTML form to database using custom template

 *  [anthonyo2](https://wordpress.org/support/users/anthonyo2/)
 * (@anthonyo2)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/html-form-to-database-using-custom-template/)
 * Hello everyone, I try to set up an HTML form that send data forms in the tables“
   contacts” in my database (the same used by WordPress).
    My script below okay 
   but it does not work … When using this template page on a WordPress page, I can
   go there and see the form show but when I click on “send” it gives me a 404 error
   on the same links as the form was … Can anyone help me …
 *     ```
       <?php // Template Name: Custom-Form ?>
       <?php get_header(); ?>
   
       <?php
       if (!empty($_POST)) {
       global $wpdb;
       $table = contacts;
       $data = array(
       'name' => $_POST['name'],
       'surname' => $_POST['name'],
       'email' => $_POST['email'],
       'number' => $_POST['number'],
       'method' => "",
       'pin' => "",
       'message' => "",
       'status' => "",
       'date' => "",
       'photo'	=> ""
       );
       $format = array(
       '%s',
       '%s',
       '%s',
       '%s',
       '%s',
       '%s',
       '%s',
       '%s',
       '%s',
       '%s'
       );
       $success=$wpdb->insert( $table, $data, $format );
       if($success){
       echo 'data has been save' ;
       }
       }
       else {
       ?>
       <form method="post">
       Nom: <input type="text" name="name">
       E-mail: <input type="text" name="email">
       Numero tel.: <input type="text" name="number">
       <input type="submit">
       </form>
   
       <?php } ?>
   
       </div><!--/container-->
   
       </div><!--/home-wrap-->
       <?php get_footer(); ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [anthonyo2](https://wordpress.org/support/users/anthonyo2/)
 * (@anthonyo2)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/html-form-to-database-using-custom-template/#post-5821408)
 * Is that a bug?
 * Sorry for my bad english…

Viewing 1 replies (of 1 total)

The topic ‘HTML form to database using custom template’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [form](https://wordpress.org/support/topic-tag/form/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [anthonyo2](https://wordpress.org/support/users/anthonyo2/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/html-form-to-database-using-custom-template/#post-5821408)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
