Title: PHP form data into a MySQL database using WordPress $wpdb
Last modified: August 20, 2016

---

# PHP form data into a MySQL database using WordPress $wpdb

 *  Resolved [I Dont use this account Anymore why is it still here](https://wordpress.org/support/users/mattyrasker/)
 * (@mattyrasker)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/php-form-data-into-a-mysql-database-using-wordpress-wpdb/)
 * Hi guys!
 * Hoping you might be able to help me out.
 * I am playing around with plugin development and would like to take data from 
   a form and put into a database that I have created.
 * The database is called music (or wp_music after adding the prefix when creating
   the database upon plugin activation, following this: [http://codex.wordpress.org/Creating_Tables_with_Plugins](http://codex.wordpress.org/Creating_Tables_with_Plugins)).
   It has three columns, ID (primary key), Album, Artist. ID is set to auto increment.
 * The plugin creates its own page in admin, which is an html doc in which has a
   very small, easy form:
 * _htmlform.html_
 *     ```
       <form action="formhtml.php" method="post">
       Album: <input type="text" name="album" />
       Artist: <input type="text" name="artist" />
       <input type="submit" />
       </form>
       ```
   
 * _formhtml.php_
 *     ```
       <?php
   
        global $wpdb
   
        $album=$_POST['album'];
        $artist=$_POST['artist'];
   
        $wpdb->insert( 'music', array( 'album' => $album, 'artist' => $artist ), array( '%s', '%s' ) )
   
       ?>
       ```
   
 * And I get an Error 500 internal server error.
 * I’ve tried replacing ‘music’ with ‘wp_music’ too.
 * Perhaps someone can steer me in the right direction? let me know if you need 
   any info!
 * Many thanks,
    Mat

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

 *  Thread Starter [I Dont use this account Anymore why is it still here](https://wordpress.org/support/users/mattyrasker/)
 * (@mattyrasker)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/php-form-data-into-a-mysql-database-using-wordpress-wpdb/#post-2840038)
 * Forgot to say, I also tried
 * `$wpdb->insert( 'music', array( 'album' => $album, 'artist' => $artist ), array('%
   s', '%s' ) )` with a semicolon at the end.
 * still no success.
 *  Thread Starter [I Dont use this account Anymore why is it still here](https://wordpress.org/support/users/mattyrasker/)
 * (@mattyrasker)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/php-form-data-into-a-mysql-database-using-wordpress-wpdb/#post-2840040)
 * Oh, and also tried
 * `$rows_affected = $wpdb->insert( 'music', array( 'album' => $album, 'artist' 
   => $artist ), array( '%s', '%s' ) );`
 *  Thread Starter [I Dont use this account Anymore why is it still here](https://wordpress.org/support/users/mattyrasker/)
 * (@mattyrasker)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/php-form-data-into-a-mysql-database-using-wordpress-wpdb/#post-2840119)
 * Starting a new thread

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

The topic ‘PHP form data into a MySQL database using WordPress $wpdb’ is closed 
to new replies.

## Tags

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

 * 3 replies
 * 1 participant
 * Last reply from: [I Dont use this account Anymore why is it still here](https://wordpress.org/support/users/mattyrasker/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/php-form-data-into-a-mysql-database-using-wordpress-wpdb/#post-2840119)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
