Jump to content

processing form on same page and then clearing the POST values


Recommended Posts

I want to process the form on the same page.  At the bottom, after </form> I have:

<?php
if(isset($_POST['myusername'])) {
echo "Your username has been added."; 
include ("connectdb.php");

$username = mysql_real_escape_string($_POST['myusername']);
$password = mysql_real_escape_string($_POST['mypassword']);

$query = "INSERT INTO members (id, username, password) VALUES('','$username', '$password')";
mysql_query($query) or die(mysql_error());
?>
<?php
}
?>

 

So it echoes "your username has been added" if there is a username value, but how do I clear this value if someone reloads the page so that sentence is not displayed and a new username can be added?

<?php
if(isset($_POST['myusername'])) {
echo "Your username has been added."; 
include ("connectdb.php");

$username = mysql_real_escape_string($_POST['myusername']);
$password = mysql_real_escape_string($_POST['mypassword']);

$query = "INSERT INTO members (id, username, password) VALUES('','$username', '$password')";
mysql_query($query) or die(mysql_error());

unset($_POST['myusername']);
unset($username);
unset($password);
}
?>

 

I assume that will work.. refreshing the page would not have a POST.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.