WordPress.org

Ready to get started?Download WordPress

Forums

Redirect after successful wpdb->query (4 posts)

  1. Kuckovic
    Member
    Posted 9 months 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 )",
        array(
            $commenturl,
            $commentname
        )
    )) 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...

    /Kuckovic

  2. Amras
    Member
    Posted 9 months 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
    Member
    Posted 9 months 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
    Member
    Posted 9 months ago #

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

Reply

You must log in to post.

About this Topic