I write 2 php pages, index.php & form.php, when user submit form in index.php, then form.php process and check whether email is duplicate, so I write in form.php like this
header('Content-type:text/html; charset=big5');
header("location:javascript://history.go(-1)");
echo "<Script language=JavaScript>alert('email exist!');</Script>";
if the email exist, page will return to index.php, I hope the input text box still keep what the user enter, and have a alert box in index.php to remind them the email exist,
But I try different way, but the alert box cannot be shown in index.php, I know nothing will output before header, I also try ob_start()
,
Can anyone teach me how can I check email duplication in form.php, and then just go back to index.php without refresh, also the user input still appear, also index.php can display an alert box to remind user, thank you!
it should be script
NOT Script
echo "<script type='text/javascript'>alert('email exist!');</script>";
EDIT : if you are redirecting back to index.php
and the alert is in form.php
so it will never fire you have to be on the same page!
if(isset($_POST['create'])) //here your submit button
{
if(isset($_REQUEST['email']))
{
$username = $_POST['email']; //// textbox value you written email
$sql = mysqli_query($conn,"select email from tablename where email='$username'");
if(mysqli_num_rows($sql)>0)
{
echo "<script>
alert('email already')
</script>";
}
else
{
//registration code
}
}
PHP is serverside scripting language and javascript is clicent side scripting language. PHP header()
function is faster than script that's why header() execution fast and it not display.