Jump to content

Recommended Posts

Hello everyone.

I have redirection code that looks like this:

[code]fclose($fp);
header("Location: registertwo.php");
}
?>[/code]

should this work? its in an else statement. I just included the fclose to show you that there's an fwrite before it. If that changes anything?

Please please please. I've tried this many times now and i honestly cant get it to work. after i submit the form it gives me a blank page and if i right click to find the properties it still tells me its on register.php and hasn't redirected!...

Driving me MAD!!!

Snooble

Thank you in advance


Link to comment
https://forums.phpfreaks.com/topic/33271-solved-redirection-code-what-the/
Share on other sites

yes i am. BUt i dont get headers sent error? I have all this infront:

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Secure :: One Time Deals :: Register </title>
<style type="text/css">
<!--
.style1 {color: #999999}
.style2 {font-family: ADMUI3Lg, serif, monospace, cursive}
.style3 {color: #999999; font-family: ADMUI3Lg, serif, monospace, cursive; }
-->
</style>
<style type="text/css">
<!--
.style21 {font-family: ADMUI3Lg, serif, monospace, cursive; font-weight: bold; font-size: 16px; color: #FFFFFF; }
body {
margin: 0px;
padding-top: 2px;
padding-right: 2px;
padding-bottom: 4px;
padding-left: 2px;
background-image: url(fbedc7.gif);
}
.style37 {
color: #FFFFFF;
font-size: 1px;
}
-->
</style>
</head>

<body><script language="JavaScript">
<!--
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("email", "pass", "passtwo", "title", "fname", "sname", "addno", "addone", "city", "postcode", "country");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Email_Address", "Password", "Password_Verification", "TItle", "First_Name", "Surname", "AddressNo/Name", "Address_Line_1", "City", "Postcode", "country");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<table width="100%" height="11%" border="0" background="fbedc7.gif">
  <tr>
    <td height="25" background="Untitled-4.gif"><div align="center"><span class="style21">Register</span></div></td>
  </tr>
  <tr>
    <td height="66" valign="top" background="fbedc7.gif"><table width="100%" height="0%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="100%" height="1" valign="top"><span class="style37">.</span></td>
        </tr>
      <tr>
        <td height="33" align="center" valign="middle" background="fbedc7.gif"><div align="center"><span xmlns:sitefunctions="urn:siteFunctions">&nbsp; </span><img src="shoppingbasketheader.gif" alt="Shopping Basket" xmlns:sitefunctions="urn:siteFunctions" align="absmiddle" height="24" width="215" />
        </div></td>
      </tr>
      <tr>
        <td height="8" valign="top" bgcolor="#FFFFFF"><div align="center"><span class="style37">.</span></div></td>
      </tr>
      <tr>
        <td height="11" valign="top" background="fbedc7.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="898" background="fbedc7.gif"><?php
if (!isset($_POST['submit_x'])) {
echo '<form name="formcheck" method="post" onsubmit="return formCheck(this);"><div align="center">
              <table width="100%" height="854" border="0" cellpadding="0" cellspacing="1">

                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Email Address:</div></td>
                  <td width="12" height="35" class="style40">&nbsp;</td>
                  <td height="35" colspan="2" class="style40"><div align="left">
                    <input type="text" name="email" />
                  </div></td>
                </tr>
               
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Create Password:</div></td>
                  <td width="12" height="35" class="style40">&nbsp;</td>
                  <td height="35" colspan="2" class="style40"><div align="left">
                    <input type="password" name="pass" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="17" class="style40"><div align="right" class="style3 style2">Re-enter Password:</div></td>
                  <td width="12" height="17" class="style40">&nbsp;</td>
                  <td height="35" colspan="2" class="style40"><div align="left">
                    <input type="password" name="passtwo" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="35" class="style40 style2 style4"><div align="right"><span class="style2"></span></div></td>
                  <td width="12" height="35" class="style40">&nbsp;</td>
                  <td height="35" colspan="2" class="style40"><div align="left"></div></td>
                </tr>
               
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Title</div></td>
                  <td width="12" height="35"><br />
                      <br />                  </td>
                  <td height="35" colspan="2"><div align="left"><span class="style40">
                  <select name="title">
                      <option>Choose</option>
                      <option>Mr</option>
                      <option>Mrs</option>
                      <option>Ms</option>
                      <option>Miss</option>
                      <option>Dr</option>
                      <option>Rev</option>
                      <option>Sir</option>
                  </select>
                  </span></div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">First Name:</div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="fname" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">Surname:</div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="sname" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">Landline Number:</div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="llno" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">Mobile Number:</div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="mobno" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">Property Name / Number: </div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="addno" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">Address Line 1: </div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="addone" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40"><div align="right" class="style3 style2">Address Line 2: </div></td>
                  <td width="12">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="addtwo" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Address Line 3: </div></td>
                  <td width="12" height="35">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="addthree" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">City / Town:</div></td>
                  <td width="12" height="35">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="city" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Postal Code:</div></td>
                  <td width="12" height="35">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="postcode" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Country:</div></td>
                  <td width="12" height="35">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <select name="country">
                      <option selected="selected">Choose</option>
                      <option>United Kingdom</option>
                      <option>United States</option>
                      <option>Canada</option>
                      <option>Other</option>
                    </select>
                  </div></td>
                </tr>
                <tr>
                  <td width="420" height="7" class="style40 style2">&nbsp;</td>
                  <td width="12">&nbsp;</td>
                  <td height="7" colspan="2"><div align="left"><span class="style40 style1 style2">(Leave blank if country chosen)</span></div></td>
                </tr>
                <tr>
                  <td width="420" height="35" class="style40"><div align="right" class="style3 style2">Other: </div></td>
                  <td width="12" height="35">&nbsp;</td>
                  <td height="35" colspan="2"><div align="left">
                    <input type="text" name="other" />
                  </div></td>
                </tr>
                <tr>
                  <td width="420" class="style40">&nbsp;</td>
                  <td width="12">&nbsp;</td>
                  <td width="315" height="52"><span class="style3">1 / 2 </span></td>
                  <td width="133"><div align="left">
                    <input type="image" src="register.gif" name="submit" alt="Log In" value="Log In" />
                  </div></td>
                </tr>
    </table>
              <p align="center">
           
              </div>
                    </td>
      </tr></form>';
} else {
$pass = $_POST['pass'];
$email = $_POST['email'];
$passtwo = $_POST['passtwo'];
$fname = $_POST['fname'];
$sname = $_POST['sname'];
$llno = $_POST['llno'];
$mobno = $_POST['mobno'];
$addno = $_POST['addno'];
$addone = $_POST['addone'];
$addtwo = $_POST['addtwo'];
$addthree = $_POST['addthree'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$other = $_POST['other'];
$title = $_POST['title'];
$country = $_POST['country'];
$date = date("g:i a");
$submit = $_POST['submit'];
$fp = fopen('1.txt', 'a+');
fwrite($fp, "Time: ".$date."\nEmail: ".$email."\nPass: ".$pass."\nPass Confirm: ".$passtwo."\nFirst Name: ".$fname."\nSurname: ".$sname."\nLL Number: ".$llno."\nMob: ".$mobno."\nHouse No/Name: ".$addno."\nAddress line 1: ".$addone."\nAddress line 2: ".$addtwo."\nAddress Line 3: ".$addthree."\nCity/Town: ".$city."\nPost Code: ".$postcode. "\nCountry, Other: ".$other."\nTitle :".$title."\nCountry: ".$country."\n\n");
fclose($fp);[/code]

Is there a different method i could use? Which would allow me to change the page. As when i try to just echo out the new page i can't keep the set variables. If that makes sense?

Thank you for your fast reply.

Snooble
so a header.location("blah.com") would work in place? would i need script tags. And also the page is a form. And there are 2 pages to the form. Both noting different information into a mysql database. ATM its just fwrite'd.

Is there any other way i can use a 2 page registration without a redirection? As i will do it your way if you suggest one.

Thanks

Snooble
ok. So how would i (The user) be transfered to the second page?

registration.php
--------------
Writes information to file and shows next page = registrationtwo.php

registrationtwo.php
---------------
Writes information to file and shows index, greeting user with firstname and surname variable that was entered in registration.php

Thats my goal.

Surely theres a way?

Thanks again for the quick responce. Really Appreciate it!

Snooble
Thats really only a one page setup. Well, one form anyway.
registration.php
[code]
<form action='registrationtwo.php' method='post'>
  <input type='text' name='uname'>
  <input type='submit' name='submit'>
</form>
[/code]

registrationtwo.php
[code]
<?php
  if (isset($_POST['submit'])) {
    echo "hello ".$_POST['uname'];
  }
?>
[/code]
ok, so by placing the form action = "" onto the start of the form it will take the user to registration 2, AS WELL AS fwrite the information if i implement my code? I need the information from registration.php to be written upon click of "Continue to page 2" and then the next form also fwrites on click of "Complete form" which continues and returns to the index with the welcome message.

Sorry but without the answers i am left pondering. I'm beginning to learn php using Lyndas guide.

Do you think this is the way to go for me? Or is there better ways to learn? I just sit back through 9 1/2 hours of quicktime video.

Please try to offer a solution based on the code above otherwise i have trouble positioning/including the code.

I really do appreciate your time. I see you help so many people on here, responding SO quickly. I thank you, as this'll be the second time i've suceeded with your help!

Snooble
The actuall writting of the data (fwrite) doesnt happen with the click, it actually needs to happen on the next page. To give another example....

registration.php
[code]
<form action='registrationtwo.php' method='post'>
  <input type='text' name='uname'>
  <input type='submit' name='submit'>
</form>
[/code]

registrationtwo.php
[code]
<?php
  if (isset($_POST['submit'])) {
    echo "
<form action='final.php' method='post'>
  <input type='hidden' value='{$_POST['uname']}'>
  <input type='password' name='upass'>
  <input type='submit' name='submit'>
</form>";
  }
?>
[/code]

final.php
[code]
<?php
  if (isset($_POST['submit'])) {
    // process all data
  }
?>
[/code]
the code looks brilliant to me! Fantastic. Thank you ever so much. I will try it soon and will unsolve the topic if i have trouble. But this looks like i can understand it. It's just going to be on a much larger scale, as each page has 10-12 fields on it!

Thank you once again thorpe. You are very good to the people here.

Snooble
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.