Reputation: 147
A simple register form with username and password and i want if the form succed to be inserted into the database to echo 'Account created'; but if the page is refreshed don't add again the registry.
I resolved the refresh problem with header('Location: signup.php');
but i can't figure out how to echo if the account was inserted in database.
$numeocupat=mysql_num_rows( mysql_query("SELECT * FROM testlog WHERE username='".$username."'"));
if($numeocupat!=0){echo 'Username already used';}
else{ $insert=mysql_query('INSERT INTO `testlog` (`username`, `password`)
VALUES ("'.$username.'", "'.$password.'")');
echo 'Account created.';
header('Location: signup.php');}
Upvotes: 1
Views: 73
Reputation: 4228
change:
$numeocupat=mysql_num_rows( mysql_query("SELECT * FROM testlog WHERE username='".$username."'"));
if($numeocupat!=0){echo 'Username already used';}
else{ $insert=mysql_query('INSERT INTO `testlog` (`username`, `password`)
VALUES ("'.$username.'", "'.$password.'")');
echo 'Account created.';
header('Location: signup.php?created=1');}
and at the start of signup.php:
if($_GET['created'])
{
echo 'Account created.';
}
Upvotes: 1
Reputation: 842
try
header( "refresh:5;url=signup.php" )
replace
header('Location: signup.php');}
Upvotes: 0