Jump to content

processing form on same page and then clearing the POST values


jeff5656

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.