gwolff2005 Posted April 25, 2009 Share Posted April 25, 2009 Hi guys I need your help. I try the whole day to do the following. I have a page and AFTER the form is submitted the page is supposed to go to another page... But instead the form is submitted but just stays, without redirecting to the next one... <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="passiontest2.php"; //--> </script> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/ Share on other sites More sharing options...
premiso Posted April 25, 2009 Share Posted April 25, 2009 window.location or location.href is what you need. But why not use header instead: <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()); header("Locaton: passiontest2.php"); } ?> And the second if was not needed, it did the same as the first if. So just put that inside there. Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819142 Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 I would love to do that the way you suggested but then it tells me always header error. That is the full code. I would really appreciate your help! <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="passiontest2.php"; //--> </script> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819143 Share on other sites More sharing options...
wildteen88 Posted April 25, 2009 Share Posted April 25, 2009 Remove the HTML tags. If you're not going to output anything to the page then there is no need for the HTML. Or move your PHP code before your HTML. Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819148 Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 @wildteen I did what you said. the code looks now teh following. Still it does not work. I am already exhausted :-( <?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() ?> <?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="passiontest2.php"; //--> </script> <?php } ?> <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> Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819154 Share on other sites More sharing options...
premiso Posted April 25, 2009 Share Posted April 25, 2009 I would love to do that the way you suggested but then it tells me always header error. That is the full code. I would really appreciate your help! Remove the <body> as wildteen said, that was my mistake. I did not notice you had that up top. Just for clarification, this should work: <?php ini_set("display_errors",1); ERROR_REPORTING(E_ALL); session_start(); require_once('Connections/Login.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() if (isset($_POST['Submit'])) { $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()); header("Locaton: passiontest2.php"); } ?> <html> <body> <?php showform(); ?> </body> </html> Would be a better way to structure your PHP code. This way you can use the header function. Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819156 Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 Hi premiso. it does not work. The style has gone away now and when I press "go on" it processes everything right and it does not show a white page but it does not go to the fsecond page (passiontest2.php) but it stays at the same page (passiontest.php) Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819162 Share on other sites More sharing options...
gwolff2005 Posted April 25, 2009 Author Share Posted April 25, 2009 i found the mistake it said locaton and not location Quote Link to comment https://forums.phpfreaks.com/topic/155634-solved-document-location-does-not-work/#findComment-819182 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.