Reputation: 22974
header('Location: ../homepage.html');
echo "<script language='javascript'> console.log('Email already exists'); </script>";
echo "<script> console.log('ccccc'); </script>";
I am just trying to create a registration form. When user tries to register with same Email Id, I want to go back to my html page and open login window[Trigger login click
].
For initial try, i just try to console some strings after redirecting the page. I don't get those strings.
If i comment out header line, I get those two strings.
How do i solve this issue? Is there any alternative for my scenario?
I have separate html and php files.
EDIT:
if (mysqli_num_rows($result1) > 0)
{
//echo "This Email is already used.";
//Write code to go back to register window
/*echo '<script type="text/javascript">
console.log("cdsafcds");
$(".login_links_login").trigger("click");
</script>';*/
$_SESSION['email_exist']="Email Already Exists";
header('Location: ../homepage.php');
}
homepage.php Part:
<?php
if(isset($_SESSION['email_exist']))
{
echo "<script language'javascript'>conosle.log('Me');</script>";
}
?>
<html>
<head>
.......
<form class="right registerForm" id="registerForm" method="POST" action="lib/registration_validate.php">
......
Upvotes: 0
Views: 70
Reputation: 650
when you use header('Location: ../homepage.php');
it wont execute the two lines afterward. That is the whole problem. You can do it either by passing variables through header like this : header('Location: ../homepage.php?log');
or setting session in your php script and use redirect afterwards.
You also need php file in order to catch the parameter you just send and use if like this :
if(isset($_GET['log'])){
echo "<script language='javascript'> console.log('Email already exists'); </script>";
echo "<script> console.log('ccccc'); </script>";
}
or :
if(isset($_SESSION['log'])){
echo "<script language='javascript'> console.log('Email already exists'); </script>";
echo "<script> console.log('ccccc'); </script>";
}
It depends on what method you used earlier. So turn your homepage.html into homepage.php and put it there.
Upvotes: 4