Guest elthomo Posted February 26, 2008 Share Posted February 26, 2008 Here is my code it submits the data ok but i cant get it to navigate to a new page with the same click too. I could really use some help and I'm sure its really simple but just cant see it. Thanks in advance. <?php $db_host = "localhost"; $db_user = "****"; $db_pwd = "****"; $db_name = "****"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #FF9933; } .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style></head> <body> <?php if (!isset($_POST['submit'])) { ?> <table width="100%"> <tr> <td bgcolor="#FF9933"><img src="Images/header2.gif" width="476" height="74" /></td> </tr> </table> <table width="800" align="center"> <tr> <td height="600 " bgcolor="#FFFFFF"><table width="500" align="center"> <tr> <td><form action="index2.php" method="post"> <span class="style1">Achternaam:</span> <input type="text" name="achternaam" /> <br /> <br /> <span class="style1">Voorletters:</span> <input type="text" name="voorletters" /> <br /> <br /> <span class="style1">Geboorte:</span> <input type="num" name="geboorte" /> <br /> <br /> <span class="style1">Postcode:</span> <input type="string" name="postcode" /> <br /> <br /> <span class="style1">Huisnummer:</span> <input type="num" name="huisnummer" /> <br /> <br /> <span class="style1">E-mail adres:</span> <input type="string" name="email" /> <br /> <br /> <span class="style1">Uw dossiernummer(zie onze brief):</span> <input type="string" name="dossiernummer" /> <br /> <br /> <input type="submit" name="submit" value="Submit!" onClick="goTo('index2.php)" /> </form></td> </tr> </table></td> </tr> </table><table width="800" align="center"> <tr> <td><img src="Images/adres2.gif" width="699" height="20" align="middle" /></td> </tr> </table> <?php } else { $achternaam = $_POST['achternaam']; $voorletters = $_POST['voorletters']; $geboorte = $_POST['geboorte']; $huisnummer = $_POST['huisnummer']; $email = $_POST['email']; $postcode = $_POST['postcode']; $dossiernummer = $_POST['dossiernummer']; mysql_query("INSERT INTO `klanten` (achternaam, voorletters, geboorte, huisnummer, email, postcode, dossiernummer) VALUES ('$achternaam', '$voorletters', '$geboorte', '$huisnummer', '$email', '$postcode', '$dossiernummer')"); } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 26, 2008 Share Posted February 26, 2008 After this line mysql_query("INSERT INTO `klanten` (achternaam, voorletters, geboorte, huisnummer, email, postcode, dossiernummer) VALUES ('$achternaam', '$voorletters', '$geboorte', '$huisnummer', '$email', '$postcode', '$dossiernummer')"); Add this: header("Location: www.your-url.com"); Quote Link to comment Share on other sites More sharing options...
haku Posted February 26, 2008 Share Posted February 26, 2008 That's not going to work, because he has already outputted headers to the browser by that point. OP: You need to move all your PHP form processing to the top of your script, BEFORE you output your <html > tag. Put all the processing script inside a similar condition to the one you have so that it looks like this: if(isset($_POST['submit'])) { // form processing script here header("Location: www.your-url.com"); } <html> // continue the rest of your script here Also, you need to post your code in [code ] tags when you post here. Its really hard to read as it is now. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 When I add the header tag it redirects me to the root of the site. So www.url.com/index.php goes to www.url.com Things that may confuse the problem is that I am currently connecting to the IP not a URL.(not sure if that will make a difference at this stage) Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 So make the URL in the header tag be the address of the page you want to access. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 I did try that but I get the error from the browser that says "The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete." The same happens with Safari. Again thanks for the speedy reply :-) Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2008 Share Posted February 27, 2008 Post your current code. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 Current code, also to note i have tried just the IP in the header too. <?php $db_host = "localhost"; $db_user = "****"; $db_pwd = "****"; $db_name = "****"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <?php if (!isset($_POST['submit'])) { header("Location: http://192.168.2.108/index.php"); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #FF9933; } .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style></head> <body> <table width="100%"> <tr> <td bgcolor="#FF9933"><img src="Images/header2.gif" width="476" height="74" /></td> </tr> </table> <table width="800" align="center"> <tr> <td height="600 " bgcolor="#FFFFFF"><table width="500" align="center"> <tr> <td><form action="index2.php" method="post"> <span class="style1">Achternaam:</span> <input type="text" name="achternaam" /> <br /> <br /> <span class="style1">Voorletters:</span> <input type="text" name="voorletters" /> <br /> <br /> <span class="style1">Geboorte:</span> <input type="num" name="geboorte" /> <br /> <br /> <span class="style1">Postcode:</span> <input type="string" name="postcode" /> <br /> <br /> <span class="style1">Huisnummer:</span> <input type="num" name="huisnummer" /> <br /> <br /> <span class="style1">E-mail adres:</span> <input type="string" name="email" /> <br /> <br /> <span class="style1">Uw dossiernummer(zie onze brief):</span> <input type="string" name="dossiernummer" /> <br /> <br /> <input type="submit" name="submit" value="Submit!" onClick="goTo('index2.php)" /> </form></td> </tr> </table></td> </tr> </table><table width="800" align="center"> <tr> <td><img src="Images/adres2.gif" width="699" height="20" align="middle" /></td> </tr> </table> <?php } else { $achternaam = $_POST['achternaam']; $voorletters = $_POST['voorletters']; $geboorte = $_POST['geboorte']; $huisnummer = $_POST['huisnummer']; $email = $_POST['email']; $postcode = $_POST['postcode']; $dossiernummer = $_POST['dossiernummer']; mysql_query("INSERT INTO `klanten` (achternaam, voorletters, geboorte, huisnummer, email, postcode, dossiernummer) VALUES ('$achternaam', '$voorletters', '$geboorte', '$huisnummer', '$email', '$postcode', '$dossiernummer')"); } ?> Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 The end goal(once I have got the form to submit data to sql and navigate to new page) is to have a set of 5 radio buttons that depending on which you click take you to a different page. One step at a time though eh :-) Quote Link to comment Share on other sites More sharing options...
kranthi117 Posted February 27, 2008 Share Posted February 27, 2008 i suggest you to use anchor element insted of radio button in that case elimenate the javascript below and just give <a href="http://someplace.com">someplace</a> as suggested by haku if(isset($_POST['submit'])) { // form processing script here header("Location: www.your-url.com"); } <html> // continue the rest of your script here but insted of header("Location: www.your-url.com"); give the radio buttons with the onclick event handler as window.location="http://someplace.com"; Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 It sounds like the page you are trying to forward the user to is forwarding the user back, and getting stuck in a loop. If the page didn't exist, you would get a 404 message. But the message you posted makes it sound like a loop problem. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 It sounds like the page you are trying to forward the user to is forwarding the user back, and getting stuck in a loop. If the page didn't exist, you would get a 404 message. But the message you posted makes it sound like a loop problem. Yes it is whats happening as fas as I can tell. If I just give the base url of the site as the header it just sits at the site index(not the index.php) Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 i suggest you to use anchor element insted of radio button in that case elimenate the javascript below and just give <a href="http://someplace.com">someplace</a> as suggested by haku if(isset($_POST['submit'])) { // form processing script here header("Location: www.your-url.com"); } <html> // continue the rest of your script here but insted of header("Location: www.your-url.com"); give the radio buttons with the onclick event handler as window.location="http://someplace.com"; Thanks for that I will try it but because this is also a learning exercise for me I would like to workout how to do it with the submit button first. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 Ok I have been looking and thinking a little more and I think the header tag maybe a bit of a "red herring" because I don't want to do a page redirect. What I want to do is a nav to a new page when I click the submit button, that currently submits the form data to the mysql database. I hope this helps you PHP gurus Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 Then set the address of the page in your form tag: <form action="path/to/file.php" method="post"> (replace path/to/file.php with the actual address of the page that processes the form information) Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 27, 2008 Share Posted February 27, 2008 Then set the address of the page in your form tag: <form action="path/to/file.php" method="post"> (replace path/to/file.php with the actual address of the page that processes the form information) I think the person Only replaced that so people don't bug their test server. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 27, 2008 Share Posted February 27, 2008 Then set the address of the page in your form tag: <form action="path/to/file.php" method="post"> (replace path/to/file.php with the actual address of the page that processes the form information) Thanks for that we have progress! but..... If I do this I am able navigate to the new page but it no longer enters the data into my mysql database Quote Link to comment Share on other sites More sharing options...
haku Posted February 27, 2008 Share Posted February 27, 2008 You have to move all the PHP that processes the script into the top of the new file. Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 28, 2008 Share Posted February 28, 2008 Ok I got it working by adding an include statement after the if(isset($_POST['submit'])) { I'm not exactly sure how it's working, but it is. next radio button navigation Quote Link to comment Share on other sites More sharing options...
Guest elthomo Posted February 28, 2008 Share Posted February 28, 2008 I would mark this as solved but I can't see the button? 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.