php code behaves different in Chrome and Mozilla browsers
Posted: Sun Mar 25, 2012 2:49 pm
I have a Create new account page. The form is in page named Register.php and once user submit it, it will go to Confirm.php, where it validates the field if everything is correct shows the " Account Created " Message.
In Chrome. The error message is shown in Register.php and once all fields are filled then only will show confirm.php. But in Mozilla, it goes to Confirm.php and shows a blank page.
My code for Register.php is :
and for Confirm.php code is :
In Chrome. The error message is shown in Register.php and once all fields are filled then only will show confirm.php. But in Mozilla, it goes to Confirm.php and shows a blank page.
My code for Register.php is :
Code: Select all
<div class="signup_form">
<form action="confirm.php" method="post" >
<?php
session_start();
if(isset($_SESSION['error']))
{
echo '<p>'.$_SESSION['error']['username'].'</p>';
echo '<p>'.$_SESSION['error']['email'].'</p>';
echo '<p>'.$_SESSION['error']['password'].'</p>';
unset($_SESSION['error']);
}
?>
<p>
<font size="3" face="arial" color="gray"> <label for="username"><b> UserName*</b> </label> </font>
<input name="username" type="text" id="username" input style="height:33px" size = "50" size="30"/>
</p>
<p>
<font size="3" face="arial" color="gray"> <label for="email"><b> E-mail Address*</b> </label> </font>
<input name="email" type="text" id="email" input style="height:33px" size = "50" size="30"/>
</p>
<p>
<font size="3" face="arial" color="gray"> <label for="password"><b> Password*</b> </label> </font>
<input name="password" type="password" id="password" input style="height:33px" size = "50" size="30"/>
</p>
<p>
<input name="submit" type="image" src="images/submit.gif" value="submit"/> </p>
</form>
</div>Code: Select all
<?php
session_start();
include('configdb.php');
if(isset($_POST['submit']))
{
if($_POST['username'] == '')
{
$_SESSION['error']['username'] = "User Name is required.";
}
if($_POST['email'] == '')
{
$_SESSION['error']['email'] = "E-mail is required.";
}
else
{
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email']))
{
$email= $_POST['email'];
$sql1 = "SELECT * FROM user WHERE email = '$email'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error($mysqli));
if (mysqli_num_rows($result1) > 0) {
$_SESSION['error']['email'] = "This Email is already used.";
}
}
else
{
$_SESSION['error']['email'] = "Your email is not valid.";
}
}
if($_POST['password'] == '')
{
$_SESSION['error']['password'] = "Password is required.";
}
if(isset($_SESSION['error']))
{
header("Location: register.php");
exit;
}
else
{
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql2 = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$password')";
$result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
if($result2)
{
echo '<div>Your account is now active. You may now <a href="login.php">Log in</a></div>';