Support » Plugins » Hacks » Redirect after successful wpdb->query

  • 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…


Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi kuckovic

    Can’t you just output some html content.

    <?php if($wpdb) : ?>
    <div><p>Website succesfully added!</p></div>
    <?php endif; ?>

    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…

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect after successful wpdb->query’ is closed to new replies.