• Hello,
    I’m trying to insert some data to DB from Add new post page. I created two fields, where user write first and last name and than click on button to send to DB, but whatever I try does not work. The code I’m using is:
    <button type="submit" name="submit">Submit</button>

    if(isset($_POST['submit'])){

    insert_player();
    }

    Function insert_player definitely work for 100%. It seems the click on a button not start function at all.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Is insert_player() function contain wp_insert_post() method

    and please be clear ^^

    Thread Starter tomas.ob

    (@tomasob)

    No, it uses <?php $wpdb->insert( $table, $data, $format ); ?> method from https://codex.ww.wp.xz.cn/Class_Reference/wpdb

    The function looks like this:

    $wpdb->insert('wp_scores',
          array(
                  'first_name'=>$match_options['first_nameP'],
                  'last_name'=>$match_options[last_nameP],
                  'forfeit'=>'1',
                  'lost'=>'1',
                  'lost_in_3'=>'1',
                  'l_gem'=>'1',
                  'l_set'=>'1',
                  'point'=>'1',
                  'v_gem'=>'1',
                  'v_set'=>'1',
                  'win'=>'1'
               ),
          array('%s','%s','%d','%d','%d','%d','%d','%d','%d','%d','%d')
                );

    I’m sure the function works.

    Ok Tom you need to this feature on front panel right?

    try this link Inserting DB

    Thread Starter tomas.ob

    (@tomasob)

    Yes, I’ll check out the link. Thank you.

    I think the problem is that button. When I call the function on page load without necessity of button click, it works great.

    Thread Starter tomas.ob

    (@tomasob)

    Anything I try does not work. My custom button simply does not execute function. Even echo not work.

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

The topic ‘Insert to DB from Add New Post’ is closed to new replies.