gwolff2005 Posted April 25, 2009 Share Posted April 25, 2009 Hi guys, after processing a form my page is supposed to go to another page. I use the code <?php if (isset($_POST['submit'])) // if form was submitted { ?> <script language="JavaScript"> <!-- document.location="passiontest.php"; //--> </script> <?php } ?> Why does it not work? Quote Link to comment Share on other sites More sharing options...
phpdragon Posted April 25, 2009 Share Posted April 25, 2009 I beleive its document.location.href="passiontest.php"; how come you dont just point your form action="passiontest.php" ?, this would have the same effect Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 @phpdragon this is my code. It still does not want to work... What is wrong??? <?php ini_set("display_errors","2"); ERROR_REPORTING(E_ALL);?> <?php require_once('Connections/Login.php'); ?> <?php session_start(); ?> <?php //You will need to update all the below variables $mysqlhost = "localhost"; $mysqluser = "guntmar"; $mysqlpass = "***"; $mysqldb = "guntmar"; $mysqltable = "users"; $username = "username"; $currentpo = "resultspo"; $currentmo = "resultsmo"; $id = $_SESSION['id']; // End Variables mysql_connect($mysqlhost, $mysqluser, $mysqlpass); mysql_select_db($mysqldb); $query = "SELECT * FROM " . $mysqltable . " WHERE username='" . $username . "'"; $result = mysql_query($query) or die("There was a mysql error"); while($row = mysql_fetch_array($result)){ $currentpo = $row['resultspo']; $currentmo = $row['resultsmo']; } function showForm () { echo <<<SHOWFORM <form id="form1" name="form1" method="post" action=""> <table width="699" border="0" align="center" cellspacing="5" class="style1"> <tr> <td colspan="3"><div align="center"><span class="style4">Your Passion Test</span></div></td> </tr> <tr> <td width="24"> </td> <td width="429"> </td> <td width="220"><div align="right">Saturday, 03/28/09</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right">$_SESSION[MM_firstname]</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right"></div></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td>1</td> <td><strong>I like talking to people. </strong><br /> </b></td> <td><div align="left"> <input name="po1" type="radio" value="0" /> 0 <input name="po1" type="radio" value="1" /> 1 <input name="po1" type="radio" value="2" /> 2 <input name="po1" type="radio" value="3" /> 3 <input name="po1" type="radio" value="4" /> 4 <input name="po1" type="radio" value="5" /> 5</div></td> </tr> <tr> <td>2</td> <td>It is important for me what other people think. </td> <td><p> <label></label> <label></label> <input name="mo2" type="radio" value="0" /> 0 <input name="mo2" type="radio" value="1" /> 1 <input name="mo2" type="radio" value="2" /> 2 <input name="mo2" type="radio" value="3" /> 3 <input name="mo2" type="radio" value="4" /> 4 <input name="mo2" type="radio" value="5" /> 5<br /> <br /> </p></td> </tr> <tr> <td>3</td> <td class="style1">My level of excitement is high right now. </td> <td><p> <label></label> <input name="mo3" type="radio" value="0" /> 0 <input name="mo3" type="radio" value="1" /> 1 <input name="mo3" type="radio" value="2" /> 2 <input name="mo3" type="radio" value="3" /> 3 <input name="mo3" type="radio" value="4" /> 4 <input name="mo3" type="radio" value="5" /> 5<br /> </p></td> </tr> <tr> <td>4</td> <td>I like solving mathematical tasks. </td> <td><input name="po4" type="radio" value="0" /> 0 <input name="po4" type="radio" value="1" /> 1 <input name="po4" type="radio" value="2" /> 2 <input name="po4" type="radio" value="3" /> 3 <input name="po4" type="radio" value="4" /> 4 <input name="po4" type="radio" value="5" /> 5</td> </tr> </table> <p align="center"> <input name="Submit" type="submit" class="style1" value="go on" /> </p> </form> SHOWFORM; }//Close showForm() ?> <!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>Your Passion Test</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #000033; } .style3 {font-family: Verdana, Arial, Helvetica, sans-serif} .style4 { font-size: 20px; color: #996600; } --> </style> </head> <body> <?php if (!isset($_POST['Submit'])) { showForm(); } else { $pagepo = ($_POST['po1'] + $_POST['po4']); $pagemo = ($_POST['mo2'] + $_POST['mo3']); $newpo = ($currentpo + $pagepo); $newmo = ($currentmo + $pagemo); $query = "Update ".$mysqltable." SET resultspo = resultspo + '".$newpo."', resultsmo = resultsmo + '".$newmo."' WHERE id = '".$_SESSION['id']."'"; mysql_query($query) or die("There was a mysql error<br />Query: {$query}<br />Error Returned: " . mysql_error()); } if (isset($_POST['submit'])) // if form was submitted { ?> <script language="JavaScript"> <!-- document.location="passiontest.php"; //--> </script> <?php } ?> //JavaScript page redirect... // Close if/else ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 25, 2009 Share Posted April 25, 2009 Use header instead. header('Location: http://yourdomain/passiontest.php'); Quote Link to comment Share on other sites More sharing options...
phpdragon Posted April 25, 2009 Share Posted April 25, 2009 or change this <form id="form1" name="form1" method="post" action=""> to <form id="form1" name="form1" method="post" action="passiontest.php"> Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 @mchl Thanks for the heaer suggestion. Hoever when I try that it tells me: Warning: Cannot modify header information - headers already sent by (output started at /home/guntmar/public_html/passiontest.php:147) in /home/guntmar/public_html/passiontest.php on line 183 Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 25, 2009 Share Posted April 25, 2009 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 @phpdragon There is a misunderstanding. The site of which I posted the code is called passiontest.php the site where it should go after processing the form is passiontest2.php. When i change now action as you suggested it does not save anymore the datas in mysql Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 Is there nothing I can write like if form is processed goto passiontest2.php Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 25, 2009 Share Posted April 25, 2009 Yes you can. Use headers as I said. Only thing you must take care of, is that there's no output before it. Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 ok maybe i dont get it i went through every tutorial but it seems i still dont get it.. When I put the header UNDER the output it does not work as you say if I put it on top of the output it goes straight to the other side without showing the information... Quote Link to comment Share on other sites More sharing options...
trq Posted April 25, 2009 Share Posted April 25, 2009 Move all your html into the showform() function, you cannot output any content before calling header. Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 Hi thorpe thanks for your help. However that does not work!! Can you please help me? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 You need to learn just basically how the HTTP protocol works. If you want the page at http://www.phpfreaks.com then you first open up a connection to 66.97.171.5 on the port 80, and you tell the machine something like this: GET / HTTP/1.1 Host: www.phpfreaks.com An empty line denotes that there are no more headers. Then the server will respond with something like this: HTTP/1.1 200 OK Date: Sat, 25 Apr 2009 10:35:00 GMT Server: Apache/2.2.8 Content-Type: text/html; charset=utf-8 *HTML SOURCE CODE HERE* Again, the an empty line denotes the end of headers. What that means is that when you're done with your headers, you're done. There can be absolutely no more. Headers first, body after. So if you send content, then the headers will have to be sent, but if the headers have been sent, then you cannot send more headers. That's the way the HTTP protocol works. Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 @manichl and thorpe I went through all the tutorials but still I don't get WHERE and WHAT I have to write in order for the form to go to the next page. Please help me. The code is <?php ini_set("display_errors","2"); ERROR_REPORTING(E_ALL);?> <?php require_once('Connections/Login.php'); ?> <?php session_start(); ?> <?php //You will need to update all the below variables $mysqlhost = "localhost"; $mysqluser = "guntmar"; $mysqlpass = "je20sa05"; $mysqldb = "guntmar"; $mysqltable = "users"; $username = "username"; $currentpo = "resultspo"; $currentmo = "resultsmo"; $id = $_SESSION['id']; $url = "http://www.guntmarwolff.com/passiontest2.php" ; // End Variables mysql_connect($mysqlhost, $mysqluser, $mysqlpass); mysql_select_db($mysqldb); $query = "SELECT * FROM " . $mysqltable . " WHERE username='" . $username . "'"; $result = mysql_query($query) or die("There was a mysql error"); while($row = mysql_fetch_array($result)){ $currentpo = $row['resultspo']; $currentmo = $row['resultsmo']; } function showForm () { echo <<<SHOWFORM <form id="form1" name="form1" method="post" action=""> <table width="699" border="0" align="center" cellspacing="5" class="style1"> <tr> <td colspan="3"><div align="center"><span class="style4">Your Passion Test</span></div></td> </tr> <tr> <td width="24"> </td> <td width="429"> </td> <td width="220"><div align="right">Saturday, 03/28/09</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right">$_SESSION[MM_firstname]</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right"></div></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td>1</td> <td><strong>I like talking to people. </strong><br /> </b></td> <td><div align="left"> <input name="po1" type="radio" value="0" /> 0 <input name="po1" type="radio" value="1" /> 1 <input name="po1" type="radio" value="2" /> 2 <input name="po1" type="radio" value="3" /> 3 <input name="po1" type="radio" value="4" /> 4 <input name="po1" type="radio" value="5" /> 5</div></td> </tr> <tr> <td>2</td> <td>It is important for me what other people think. </td> <td><p> <label></label> <label></label> <input name="mo2" type="radio" value="0" /> 0 <input name="mo2" type="radio" value="1" /> 1 <input name="mo2" type="radio" value="2" /> 2 <input name="mo2" type="radio" value="3" /> 3 <input name="mo2" type="radio" value="4" /> 4 <input name="mo2" type="radio" value="5" /> 5<br /> <br /> </p></td> </tr> <tr> <td>3</td> <td class="style1">My level of excitement is high right now. </td> <td><p> <label></label> <input name="mo3" type="radio" value="0" /> 0 <input name="mo3" type="radio" value="1" /> 1 <input name="mo3" type="radio" value="2" /> 2 <input name="mo3" type="radio" value="3" /> 3 <input name="mo3" type="radio" value="4" /> 4 <input name="mo3" type="radio" value="5" /> 5<br /> </p></td> </tr> <tr> <td>4</td> <td>I like solving mathematical tasks. </td> <td><input name="po4" type="radio" value="0" /> 0 <input name="po4" type="radio" value="1" /> 1 <input name="po4" type="radio" value="2" /> 2 <input name="po4" type="radio" value="3" /> 3 <input name="po4" type="radio" value="4" /> 4 <input name="po4" type="radio" value="5" /> 5</td> </tr> </table> <p align="center"> <input name="Submit" type="submit" class="style1" value="go on" /> </p> </form> SHOWFORM; }//Close showForm() ?> <!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>Your Passion Test</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #000033; } .style3 {font-family: Verdana, Arial, Helvetica, sans-serif} .style4 { font-size: 20px; color: #996600; } --> </style> </head> <body> <?php if (!isset($_POST['Submit'])) { showForm(); } else { $pagepo = ($_POST['po1'] + $_POST['po4']); $pagemo = ($_POST['mo2'] + $_POST['mo3']); $newpo = ($currentpo + $pagepo); $newmo = ($currentmo + $pagemo); $query = "Update ".$mysqltable." SET resultspo = resultspo + '".$newpo."', resultsmo = resultsmo + '".$newmo."' WHERE id = '".$_SESSION['id']."'"; mysql_query($query) or die("There was a mysql error<br />Query: {$query}<br />Error Returned: " . mysql_error()); } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 I went through all the tutorials but still I don't get WHERE and WHAT I have to write in order for the form to go to the next page. Please help me. You were already told several times in this topic. Quote Link to comment Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 Hi Daniel. That answer was really helpful. Thanks! Quote Link to comment 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.