pancgom Posted April 13, 2008 Share Posted April 13, 2008 Hi, I have this form which has page1Form.php as a self processing form and there is another page2Form.php which needs to be shown once the page1Form.php is submitted. The problem i have is the form works when i submit the information entered it is also appended to the database but it does not show the page2Form.php...can some one please help me with how do i submit information to the database at the same time go to the page2Form.php to fill in more details. Thanks. <?php session_start(); ?> <head> <title>sddsdd</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link href="CSS/GraduateProgram.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); 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+".location='"+args[i+1]+"'"); } //--> </script> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <?php $db_host = "localhost"; $db_user = "xxxx"; $db_pwd = "xxxx"; $db_name = "xxxx"; 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"> </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')"); header ("Location: pg1.php"); } ?> <p align="center">1/12</p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/100894-page1formphp-to-page2formphp/ Share on other sites More sharing options...
AP81 Posted April 13, 2008 Share Posted April 13, 2008 Why do you post the page to itself? There are two ways to fix this: 1) Change the form action in to page2Form.php to page2Form.php <?php <form action="page2Form.php" method="post" > ?> In page2Form.php, you would do this: <?php $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')"); ... ?> 2) you can call redirect the page using JavaScript <?php mysql_query("INSERT INTO `PersonnelDetails` (Username, Password, PasswordQuestion, PasswordAnswer) VALUES ('$Username', '$Password', '$PasswordQuestion','$PasswordAnswer')"); echo "<script>document.location.href = 'page2Form2.php'; </script>"; ?> IMO it is hack programming to submit a form, then redirect to another form... so I'm not sure why you want to do this exactly. Quote Link to comment https://forums.phpfreaks.com/topic/100894-page1formphp-to-page2formphp/#findComment-515972 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.