• 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: https://codex.www.ads-software.com/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)
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.