• Hi there, I am new in wordpress plugin writing but have managed to get a lot of stuff done already.

    I have one question regarding to adding data to the database.

    I have a form on one of my admin subpages:

    <form id="addgal" action="" method="post">
    
            <input type="text" name="title"/>
    
            <input type="text" name="description"/>
    
            <input name="submit" type="submit" id="submit" value="Add" />
            </form>

    and a function to add the contents of these fields into the database:

    function add_album() {
    
    		global $wpdb;
    
    		$sql = "INSERT INTO " . $wpdb->prefix . "gallery
                      (id, title, description) VALUES (
                      '" . $wpdb->insert_id . "',
                      '" . $wpdb->escape($_POST['title']) . "',
                      '" . $wpdb->escape($_POST['description']) . "'
                      )";
    
            $wpdb->query($sql);		
    
    	}

    But i am having a really hard time to make sure the form passes the data to this function, i’ve tried all sorts of url’s in the form action field but I cant seem to make it work. Maybe i’m just plain stupid or misunderstanding how wordpress handles this, but i’d appreciate some directions 🙂

    Thanks!

  • The topic ‘Adding data to database’ is closed to new replies.