Lee-Bartlett Posted October 2, 2008 Share Posted October 2, 2008 Ok im not sure wot i am doing wrong here, i can redirect a form to a differnt page, but for some reasson this isnt working correctly. I would like redirect my form to home.php instead of form.php, but if i take out form.php out the form action, it doesnt give any data to my database. here is all my code THIS IS THE USERFORM.PHP <?php //db connection require_once("includes/db_connection.php"); //end of db connection ?> <html> <head> </heaD> <body> <form name="form" method="post" action="includes/form.php"> <input type="hidden" name="redirect" value=""> <table width="418" align="left" cellpadding="0" cellspacing="0"> <tr> <td width="157"> Name:</td> <td width="259"><label for="name"></label> <input type="text" name="name" id="name"></td> </tr> <tr> <td>Email:</td> <td><label for="email"></label> <input type="text" name="email" id="email"></td> </tr> <tr> <td>WiFi Business Name:</td> <td><label for="buissnes_name"></label> <input type="text" name="buissnes_name" id="buissnes_name"></td> </tr> <tr> <td>WiFi Location;</td> <td><label for="textfield"></label> <input type="text" name="location" id="location"></td> </tr> <tr> <td>Free or Paid:</td> <td>Free<input type="radio" name="type" id="type" value="free"> <label for="radio"></label> Paid<input type="radio" name="type" id="type" value="paid"> <label for="radio2"></label></td> </tr> <tr> <td> </td> <td><label for="button"></label> <input type="submit" name="button" id="button" value="Submit"> <label for="button2"></label> <input type="reset" name="button2" id="button2" value="Reset"> <label for="sub"></label></td> </tr> </table> </form> <?php // db table connection include("includes/form.php"); //end of db table connection ?> </body> </html> <?php mysql_close($connect) ?> THIS IS FORM.PHP <?php require_once('db_connection.php'); ?> <?php $sql="INSERT INTO tblbasicform (name, email, buissnes_name, location, type) VALUES ('$_POST[name]','$_POST[email]','$_POST[buissnes_name]','$_POST[location]','$_POST[type]')"; if (!mysql_query($sql,$connect)) { die('Error: ' . mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/ Share on other sites More sharing options...
CroNiX Posted October 3, 2008 Share Posted October 3, 2008 In form.php... <?php if (!mysql_query($sql,$connect)) { die('Error: ' . mysql_error()); } else { header("Location: http://www.yoursite.com/location/of/home.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656021 Share on other sites More sharing options...
Lee-Bartlett Posted October 3, 2008 Author Share Posted October 3, 2008 Soon as u posted that i thought of headers ty works gr8 Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656022 Share on other sites More sharing options...
Lee-Bartlett Posted October 3, 2008 Author Share Posted October 3, 2008 Got small problem with that, forgot to mention, the userform is already linked from another page before that. So i now get on, userform page Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Website\userform.php:2) in C:\xampp\htdocs\Website\includes\form.php on line 14 Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656023 Share on other sites More sharing options...
johnsmith153 Posted October 3, 2008 Share Posted October 3, 2008 You can't ouput anything to html before PHP attempts to header redirect. Ie. You can not: echo "hello" header you could: $storeOutputText="hello" (etc.) header (if needed) echo $storeOutputText etc. They get funny on here about header questions, read the note at the top of the topics listings page which explains all. Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656042 Share on other sites More sharing options...
Lee-Bartlett Posted October 3, 2008 Author Share Posted October 3, 2008 That confused me, and i dont think the stickie solved my problem Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656045 Share on other sites More sharing options...
Lee-Bartlett Posted October 3, 2008 Author Share Posted October 3, 2008 is there a better way to do what i need to do without header? Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656048 Share on other sites More sharing options...
xtopolis Posted October 3, 2008 Share Posted October 3, 2008 It looks like you're including the form.php on the form page itself (userform.php) (without any values being entered yet!) Why include form.php on userform.php if the form action is form.php? If you take out that include, the page still goes to form.php, and you can use the header that was provided to you. It has the error because you show the form before including form.php which tries to add that header call unsuccessfully (because you've already outputted to the page). ** If you're going to do it that way, structure your page like this: <?php if(isset($_POST['button'])) { //db connection require_once("includes/db_connection.php"); //process form require("includes/form.php"); }// ^--post is set ?> <html> <head> </heaD> <body> ... That way you can still have the header call in form.php, because nothing will have been displayed yet. also, change the action of the form <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656050 Share on other sites More sharing options...
Lee-Bartlett Posted October 3, 2008 Author Share Posted October 3, 2008 That got rid of the header problem on the userform page, but it doesnt direct to home.php form.php has this Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Website\includes\form.php:1) in C:\xampp\htdocs\Website\includes\form.php on line 1 Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656058 Share on other sites More sharing options...
xtopolis Posted October 3, 2008 Share Posted October 3, 2008 What is the output? Does it show anything on the page, or only the error? Post the source of your userform.php and form.php separately, using code tags so that we can see how you're doing it now. Quote Link to comment https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656072 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.