Forum Moderators: coopster

Message Too Old, No Replies

How do i go from one form page to another after submitting it

page1Form.php to page2Form.php

         

pancgom

5:56 am on Apr 13, 2008 (gmt 0)

10+ Year Member



I have a page1.php which is a form and i want to be able to go to page2.php when i click submit in page1.php.?
How do i do that ...my page1.php is a self processing form it will submit the data to the database and then go to the page2.php.

Thanks much for any help

Habtom

6:29 am on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



After page1.php finishes processing the code, redirect the page to page2.php.

header("location: page2.php");

Make sure you don't have any output before you send the header.

pancgom

6:49 am on Apr 13, 2008 (gmt 0)

10+ Year Member



Below is what i have....i did use the header
after the form processor..but i still get the error

<?php header ("location: pg1.php");?> could you please let me know here to place it for me my page is as below...

Error i am getting

Warning: Cannot modify header information - headers already sent by (output started at /var/www/bergeform/index.php:3) in /var/www/bergeform/index.php on line 3

<?php
session_start();
?>

<head>

<title>#*$!xx</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link href="CSS/program.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 ¦¦ p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min ¦¦ max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<br>
<?php

$db_host = "localhost";
$db_user = "#*$!xx";
$db_pwd = "#*$!#*$!";
$db_name = "#*$!#*$!";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);

?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" >

<table width=1000 border="0" align="center" cellpadding=3 cellspacing="0" style="border:1px solid #999999;">
<tr>
<td height="30" colspan="2" valign="middle" bgcolor="#FF933" class="BodyTextHeaders">User Login / Registration</td>
</tr>
<?php
if (!isset($_POST['submit'])) {
?>
<tr>
<td width=200 valign="middle" bgcolor="#E8E8E8" class="BodyText"><strong>Username
:</strong></td>
<td width="786" valign="top" bgcolor="#E8E8E8" class="BodyText">


<input name="Username" type="text" class="BodyText" id="Username" value="Enter email address" size="50"></td>
</tr>

<tr>
<td width=200 valign="middle" class="BodyText"><strong>Password :</strong></td>
<td valign="top" class="BodyText"><p>
<label></label>
<input name="Password" type="password" id="Password" size="50">
</p></td>
</tr>

<tr>
<td valign="middle" bgcolor="#E8E8E8" class="BodyText" ><strong>Password
Assistance Question :</strong></td>
<td valign="bottom" bgcolor="#E8E8E8" class="BodyText" ><p>
<input name="PasswordQuestion" type="text" id="PasswordQuestion" size="50">
</p></td>
</tr>

<tr>
<td valign="middle" class="BodyText"><strong>Password Assistance Answer :</strong></td>
<td valign="bottom" class="BodyText"><p>
<input name="PasswordAnswer" type="text" id="PasswordAnswer" size="50">
</p> </td>
</tr>

<tr>
<td valign="middle" bgcolor="#E8E8E8" class="BodyText">&nbsp;</td>
<td valign="top" bgcolor="#E8E8E8" class="BodyText"><p><a href="#">Forgot Password</a> ¦ <a href="#">Help</a></p>
<p>Please keep your Password confidential. You will need it to access the following
online facilities related to this application :</p>
<ul>
<li >Online Status Enquiry</li>
<li >Online Change of Contact Details</li>
<li >Online Reply to CQT Offer</li>
</ul></td>
</tr>

</table>

<p align="center">
<input name="submit" type="submit" class="BodyText" onClick="MM_validateForm('Username','','RisEmail','Password','','R','PasswordQuestion','','R','PasswordAnswer','','R');return document.MM_returnValue" value="Next">
<input name="submit" type="submit" class="BodyText" value="Submit" onClick="MM_validateForm('Username','','RisEmail','Password','','R','PasswordQuestion','','R','PasswordAnswer','','R');return document.MM_returnValue" >
<input name="reset" type="reset" class="BodyText" value="Clear Form">
</p>

</form>
<?php
}
else {
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$PasswordQuestion = $_POST['PasswordQuestion'];
$PasswordAnswer = $_POST['PasswordAnswer'];

mysql_query("INSERT INTO `PersonnelDetails` (Username, Password, PasswordQuestion, PasswordAnswer) VALUES ('$Username', '$Password', '$PasswordQuestion','$PasswordAnswer')");

}

?>

<p align="center">1/12</p>
</body>
</html>

Habtom

8:55 am on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



  • Based on the logic you mentioned, right at this end of this block:
    $Username = $_POST['Username'];
    $Password = $_POST['Password'];
    $PasswordQuestion = $_POST['PasswordQuestion'];
    $PasswordAnswer = $_POST['PasswordAnswer'];
    mysql_query("INSERT INTO `PersonnelDetails` (Username, Password, PasswordQuestion, PasswordAnswer) VALUES ('$Username', '$Password', '$PasswordQuestion','$PasswordAnswer')");

    Related Issue

  • Your SQL statement is directly constructed from the input you got from the form, which might not be clean, and could be risky.
  • pancgom

    9:04 am on Apr 13, 2008 (gmt 0)

    10+ Year Member



    Hi,

    Thanks for you reply... but my immediate need is how do i go to page2Form.php from page1Form.php after i submit my page1Form.php...

    Please help me with this thanks.

    Habtom

    9:10 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    $Username = $_POST['Username'];
    $Password = $_POST['Password'];
    $PasswordQuestion = $_POST['PasswordQuestion'];
    $PasswordAnswer = $_POST['PasswordAnswer'];
    mysql_query("INSERT INTO `PersonnelDetails` (Username, Password, PasswordQuestion, PasswordAnswer) VALUES ('$Username', '$Password', '$PasswordQuestion','$PasswordAnswer')");
    header("location: page2.php");

    pancgom

    9:23 am on Apr 13, 2008 (gmt 0)

    10+ Year Member



    I get this error as below...

    The requested URL /form/<br /><b>Warning</b>: Cannot modify header information - headers already sent by (output started at /var/www/form/index.php:9) in <b>/var/www/form/index.php</b> on line <b>132</b><br /> was not found on this server.

    Habtom

    10:40 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Sent you a SM.

    I have rearranged the code for you so that it doesn't give any output prior the line holding the header function.

    pancgom

    10:57 am on Apr 13, 2008 (gmt 0)

    10+ Year Member



    error again... :-(

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/bergeform/test3.php:7) in /var/www/bergeform/test3.php on line 107

    Warning: Cannot modify header information - headers already sent by (output started at /var/www/bergeform/test3.php:7) in /var/www/bergeform/test3.php on line 107

    Habtom

    11:11 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Replied to your SM, session_start() removed, I don't see a reason why you should use it on this particular case.

    henry0

    11:13 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    in your php.ini
    allow for OB (output buffering)
    then you can have a header (redirect) wherever.

    pancgom

    11:18 am on Apr 13, 2008 (gmt 0)

    10+ Year Member




    error again....i did remove the session_start(); but after it accepts the data the page gives the error as below...it still not taking me to the next page...

    Warning: Cannot modify header information - headers already sent by (output started at /var/www/bergeform/index.php:7) in /var/www/bergeform/index.php on line 193

    Habtom

    11:23 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    henry0 has a point.

    If you are not in a position to edit the php.ini you can also use the functions ob_start() [us2.php.net] and ob_end_flush() [us2.php.net] in your script.

    Get the on header here [us2.php.net]

    pancgom

    11:28 am on Apr 13, 2008 (gmt 0)

    10+ Year Member



    I can edit it php.ini ..can u tell me how...please

    Habtom

    11:28 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    I don't see the reason why you should get that error.

    You might want only to get rid of that error, but if you go through what has been said yet, you might find out the errors by your own.

    Sticky me the current code and I will go through it for now.

    Habtom

    11:32 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Find output_buffering and set it to on.

    henry0

    11:34 am on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    do not forget restarting Apache

    pancgom

    11:46 am on Apr 13, 2008 (gmt 0)

    10+ Year Member



    PERFECTTOO IT WORKED....IT WORKED.....FINALLY..BUT THIS JUST A THE TIP OF THE ICE BERG THAT I AM TRYING TO CRACK...I WILL BE POSTING ALL NIGHT I GUESS...SORRY GUYS IF I HAD BEEN POSTING LIKE MAD..... THANKS A LOT FOR THE HELP SO FAR...

    Habtom

    12:06 pm on Apr 13, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Glad you got it working, did you edit the php.ini?

    If you are working locally right now, but have a shared hosting on the live server, you might have no chance to edit the php.ini.

    [edited by: Habtom at 12:09 pm (utc) on April 13, 2008]

    pancgom

    12:14 pm on Apr 13, 2008 (gmt 0)

    10+ Year Member



    Yes i did edit the php.ini file...