Hello everyone,
I have a problem with redirecting the user to a different page using the function Header.I have a form where the user complete his/her details in order to register in the website(register.php).The page register.php checks to see if specific fields has been filled in and if the data type that the user entered is the correct ones.If the details are correct then a message appers welcoming the user and then redirecting to another page to the basket.php in order to buy the items.
In order to redirect to another page I used the “header”
[code=php]header (“Location: http://”. $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]) . “/basket.php”);
The problem is that when i use the header is not being redirected.
Here is the code for all the page:
[code=html]
<table width=”717″ border=”0″ align=”center” cellspacing=”4″>
<tr>
<td><span class=”generalfont”><img src=”registeronline.jpg” width=”185″ height=”19″ /><br><br>
Once you have registered, you will be able to log in to your account and buy online. We will also keep you up to date with our new ranges and special offers. <br>
<br>
Simply fill in the form or click autofill on your google toolbar. </span></td>
</tr>
</table>
<br>
<form name=”register” method=”post” action=”<? echo $_SERVER[‘PHP_SELF’]; ?>”>
<table width=”406″ border=”0″ align=”center”>
<tr>
<td><label class=”generalfont”>Title:</label></td>
<td>
<select name=”title” class=”generalfont” >
<option value=”Ms”>Ms</option>
<option value=”Mrs”>Mrs</option>
<option value=”Miss”>Miss</option>
<option value=”Mr”>Mr</option>
<option value=”Dr”>Dr</option>
<option value=”Prof”>Prof</option>
</select> </td>
<td><label class=”generalfont”>Address:</label></td>
<td><input name=”address” type=”text” class=”generalfont” ></td>
</tr>
<tr>
<td> <label class=”generalfont” >First Name:</label></td>
<td><input name=”firstname” type=”text” class=”generalfont” ></td>
<td><label class=”generalfont” >Town:</label></td>
<td><input name=”town” type=”text” class=”generalfont” ></td>
</tr>
<tr>
<td><label class=”generalfont” >Last Name:</label></td>
<td><input name=”lastname” type=”text” class=”generalfont”></td>
<td><label class=”generalfont” >County:</label></td>
<td><input name=”county” type=”text” class=”generalfont”></td>
</tr>
<tr>
<td><label class=”generalfont”>E-mail:</label></td>
<td><input name=”email” type=”text” class=”generalfont”></td>
<td><label class=”generalfont”>Postcode:</label></td>
<td><input name=”postcode” type=”text” class=”generalfont”></td>
</tr>
<tr>
<td><label class=”generalfont” >Username:</label></td>
<td><input name=”username” type=”text” class=”generalfont”></td>
<td><label class=”generalfont” >Telephone:</label></td>
<td><input name=”telephone” type=”text” class=”generalfont”></td>
</tr>
<tr>
<td><label class=”generalfont”>Password:</label></td>
<td><input name=”password” type=”password” class=”generalfont”></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label class=”generalfont”>Confirm password:</label></td>
<td><input name=”confirm” type=”password” class=”generalfont”></td>
<td colspan=”2″><input name=”submit” type=”image” src=”register.jpg” class=”generalfont” value=”Register” /></td>
</tr>
</table>
<table width=”406″ border=”0″ align=”center”>
<tr>
<td>
[code=php]
<? if (isset($_POST[‘submit_x’]))
{//If submit button has been clicked
//First check if there is data and is valid
//check for the firstname
if (eregi (“^[[:alpha:].’ -]{2,15}$”, stripslashes(trim($_POST[‘firstname’]))))
{
$firstname= $_POST[‘firstname’];
}else {
$firstname= FALSE;
echo ‘<span class=”errorregister”>- Please enter your firstname</span> <br>’ ;
}
//check for the lastname
if (eregi(“^[[:alpha:].’ -]{2,30}$”, stripslashes(trim($_POST[‘lastname’]))))
{
$lastname= ($_POST[‘lastname’]);
}else {
$lastname= FALSE;
echo ‘<span class=”errorregister”> – Please enter your lastname </span><br>’;
}
//check for the email
if (eregi(“^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*$”, stripslashes(trim($_POST[’email’]))))
{
$email=($_POST[’email’]);
}else {
$email= FALSE;
echo ” <span class=”errorregister”> – Please enter a valid email address </span> <br>”;
}
//check for the username
if (eregi(“^[[:alnum:]_]{4,20}$”, stripslashes(trim($_POST[‘username’]))))
{
$username=($_POST[‘username’]);
}else {
$username= FALSE;
echo “<span class=”errorregister” > – Please enter a valid username </span><br>”;
}
//check for the password
if (eregi(“^[[:alnum:]]{1,8}$”, stripslashes(trim($_POST[‘password’]))))
{
if ($_POST[‘password’]==$_POST[‘confirm’])
{
$password=($_POST[‘password’]);
}else
{
$password=FALSE;
echo “<span class=”errorregister”> – Your password did not match the confirmed password </span><br>”;
}
}
else {
$password=FALSE;
echo “<span class=”errorregister”> – Please enter a valid password </span><br>”;
}
if ($firstname && $lastname && $username && $password && $email)
{
$queryUsername=”Select * from Customers where username=’$username'”;
$rsUsername=@mysql_query($queryUsername);
if(mysql_num_rows($rsUsername)==0) //if it is available
{
//Add the user
$query=”Insert into users(`prefix`,`user`, `pass`, `first`, `last`, `email`,`address`, `town`,`county`,`postcode`,`tel`)
values (‘$title’,’$username’,’$password’,’$firstname’,’$lastname’,’$email’,’$_POST[address]’,’$_POST[town]’,
‘$_POST[county]’,’$_POST[postcode]’,’$_POST[telephone]’)”;
$rs=@mysql_query($query);//Run the query
if ($rs)//If it ran ok
{
echo “<span class=”generalfont”>”.$firstname .” thank you for signing in the website </span>”;
header (“Location: http://”. $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]) . “/basket.php”);
}
else
{ //if it was not run
echo “<p class=”errorregister”> You could not be registered. Sorry for any incovenience. </p>”;
}
}
else { //the username is not available
echo “<p class=”errorregister”> That username is already taken. Please choose another. </p>”;
}
mysql_close();
}
else { //if one of the data test failed
echo “<p class=”errorregister”> Please try again.</p>”;
}
}//end the submit conditional (if the user submit the form)
?>
</td>
</tr>
</table>
</form>
I would appreciate if you could helped me solve it,either using header or any other idea.
Thanks,
Xenia