Redirect after successful wpdb->query (4 posts)

  1. Kuckovic
    Posted 1 year ago #

    Hi all!

    I really hope someone can help me.
    I'm developing a plugin, but now I'm stuck.

    When I add something to my database through a form, I would like my code to automatically refresh the page with a "Success" message.

    How can I do that?

    Here's my "query code":

    $commenturl = mysql_real_escape_string($_POST['comment_url']);
    $commentname = mysql_real_escape_string($_POST['comment_name']);
    if (!wp_verify_nonce($_POST['_wpnonce'],'cr_field_nonce') ) { wp_die('Oops, your nonce didn\'t verify. So there.'); }
    else {
    $wpdb->query( $wpdb->prepare(
        "INSERT INTO $table_name (crurl, crname) VALUES ( %s, %s )",
    )) or wp_die(mysql_error());
    if($wpdb) {
    	wp_die('Website succesfully added!');

    As you can see, I'm using "wp_die" for now to tell the user that the website has been added.... But that's not the way I want it to work...


  2. Amras
    Posted 1 year ago #

    Hi kuckovic

    Can't you just output some html content.

    <?php if($wpdb) : ?>
    <div><p>Website succesfully added!</p></div>
    <?php endif; ?>
  3. Kuckovic
    Posted 1 year ago #

    Hi Amras,

    Sure I can, but that won't reload my page :/
    And I can't use "header("location:")" either.

    Som Im'm kindda stuck here...

  4. Amras
    Posted 1 year ago #

    But way do you need to reload ? when you just want to show a message.

Topic Closed

This topic has been closed to new replies.

About this Topic