localhost Posted June 21, 2006 Share Posted June 21, 2006 I need to have this code redirect them to index.php once they click submit, I would like to do this as simple as possible.CODE:[code]<?phpinclude('global/global_header.php'); include('ban.php');include('includes/connect.php');$name = $_POST['name'];$email = $_POST['email'];$subject = $_POST['subject'];$message = $_POST['message'];$ipaddress = $_SERVER['REMOTE_ADDR'];$sentdate = date('m/d/Y');if($name==NULL || $email==NULL || $subject==NULL || $message==NULL) {echo ' All fields must be fulfilled ';} else {$query = "INSERT INTO contact (`name`, `email`, `subject`, `message`, `ipaddress`, `sentdate`) VALUES ('$name', '$email', '$subject', '$message', '$ipaddress', '$sentdate')";$result = mysql_query($query) or die('Could not insert details into database');include('global/global_footer.php');}if(isset($_POST['submit'])){echo "success message";}?><form action="" method="POST">Name:<input type="text" name="name" /><Br />eMail:<input type="text" name="email" /><Br />Subject:<input type="text" name="subject" /><br />Message:<input type="text" name="message" /><br /><input type="submit" name="submit" value="Contact" /></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/ Share on other sites More sharing options...
Caesar Posted June 21, 2006 Share Posted June 21, 2006 This:[code]<form action="" method="POST">[/code]Needs to be more like this:[code]<form method="post" action="index.php">[/code]...You have to define where the information in the form is being posted to.Edit: Wait,....is this form on "index.php" too? If that is the case, you also need to add an if statement so the code at the begining of the page executes only when the form is submitted. In which case, the form tag can actually look like this:[code]<form method="post" action="<?php $PHP_SELF ?>">[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48233 Share on other sites More sharing options...
localhost Posted June 21, 2006 Author Share Posted June 21, 2006 the script itself works...and the action is "" because its that php file i just need to make it so once it submits the form...it redirects them to the index page Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48234 Share on other sites More sharing options...
Caesar Posted June 21, 2006 Share Posted June 21, 2006 Just an example but, below the submit button in your form, add something like:[code]<input type="hidden" name="myform" value="1">[/code]Then in your if statement in your PHP code at the top, add something like:[code]if ($_POST[myform] == 1) {//--Code that needs to be executed here}[/code]I mean, you can do this diferently....but that should get you going in the right direction. Also...note my edit in the above post I made. Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48239 Share on other sites More sharing options...
localhost Posted June 21, 2006 Author Share Posted June 21, 2006 hmm...this lineif ($_POST[redirect] == 1) {gives me this error:Parse error: parse error, unexpected T_STRING, expecting ',' or ';' Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48243 Share on other sites More sharing options...
Caesar Posted June 21, 2006 Share Posted June 21, 2006 [!--quoteo(post=386602:date=Jun 21 2006, 04:56 PM:name=Caesar)--][div class=\'quotetop\']QUOTE(Caesar @ Jun 21 2006, 04:56 PM) [snapback]386602[/snapback][/div][div class=\'quotemain\'][!--quotec--]Just an example but, below the submit button in your form, add something like:[code]<input type="hidden" name="myform" value="1">[/code]Then in your if statement in your PHP code at the top, add something like:[code]if ($_POST[myform] == 1) {//--Code that needs to be executed here}[/code]I mean, you can do this diferently....but that should get you going in the right direction. Also...note my edit in the above post I made.[/quote]Show me the entire updated code you have. Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48245 Share on other sites More sharing options...
localhost Posted June 21, 2006 Author Share Posted June 21, 2006 it wont let me post...it gives me this error even when i use the code tagsAn appropriate representation of the requested resource /forums/index.php could not be found on this server. Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48251 Share on other sites More sharing options...
Caesar Posted June 21, 2006 Share Posted June 21, 2006 Wow. :-) Try to PM me the code.Just make sure the "if" stement wraps around the code you need executed. I see you already have one in there, to show a successfull submit. But if this is all on the same PHP file...you only want the code to execute, if the form is submitted. This isn't a question of redirection. And also, I asked whether this was all on the same page/file. Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48255 Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 Just add...[code]header("Location : index.php");[/code]After your query is executed.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]But if this is all on the same PHP file...you only want the code to execute, if the form is submitted.[/quote]Yeah... this code really is a mess. Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48257 Share on other sites More sharing options...
localhost Posted June 21, 2006 Author Share Posted June 21, 2006 yeah istillg et the erorr trying to PM it...so here is a link to the txt file with it:[a href=\"http://www.dotomega.com/forums/contact.txt\" target=\"_blank\"]http://www.dotomega.com/forums/contact.txt[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48264 Share on other sites More sharing options...
Caesar Posted June 21, 2006 Share Posted June 21, 2006 Ok...now that I can see your code. I ask this....do you want this form to post to the same file it is in...and then redirect to another page once it's done executing? Is that the goal here? Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48270 Share on other sites More sharing options...
localhost Posted June 21, 2006 Author Share Posted June 21, 2006 well i want it to post, the insert the data into the database using the INSERT query...and then redirect once its done executing.that is the goal. Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48271 Share on other sites More sharing options...
Caesar Posted June 21, 2006 Share Posted June 21, 2006 Try this:[code]<?phpif(isset($_POST['submit'])) {include('global/global_header.php'); include('ban.php');include('includes/connect.php');$name = $_POST['name'];$email = $_POST['email'];$subject = $_POST['subject'];$message = $_POST['message'];$ipaddress = $_SERVER['REMOTE_ADDR'];$sentdate = date('m/d/Y');if($name==NULL || $email==NULL || $subject==NULL || $message==NULL) {echo ' All fields must be fulfilled ';} else {$query = "INSERT INTO contact (`name`, `email`, `subject`, `message`, `ipaddress`, `sentdate`) VALUES ('$name', '$email', '$subject', '$message', '$ipaddress', '$sentdate')";$result = mysql_query($query) or die('Could not insert details into database');header("Location: index.php");}echo "success message";}echo"<form action=\"$PHP_SELF\" method=\"POST\">Name:<input type=\"text\" name=\"name\" /><Br />eMail:<input type=\"text\" name=\"email\" /><Br />Subject:<input type=\"text\" name=\"subject\" /><br />Message:<input type=\"text\" name=\"message\" /><br /><input type=\"submit\" name=\"submit\" value=\"Contact\" /></form>";include('global/global_footer.php');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48272 Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 Your code is failry problematic. Use this as an example...[code]<?php include 'ban.php'; if (isset($_POST['submit'])) { include 'includes/connect.php'; $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE; $email = (isset($_POST['email'])) ? $_POST['email'] : FALSE; $subject = (isset($_POST['subject'])) ? $_POST['subject'] : FALSE; $message = (isset($_POST['message'])) ? $_POST['message'] : FALSE; $ipaddress = $_SERVER['REMOTE_ADDR']; $sentdate = date('m/d/Y'); if ($name && $email && $subject && $message) { $query = "INSERT INTO contact (`name`, `email`, `subject`, `message`, `ipaddress`, `sentdate`) VALUES ('$name', '$e if (mysql_query($query)) { header("Location: index.php"); } else { echo "Could not insert details into database"; } } else { echo "All fields must be fulfilled"; } } else { include 'global/global_header.php'; echo " <form action=\"\" method=\"POST\"> Name:<input type=\"text\" name=\"name\" /> <br /> eMail:<input type=\"text\" name=\"email\" /> <br /> Subject:<input type=\"text\" name=\"subject\" /> <br /> Message:<input type=\"text\" name=\"message\" /> <br /> <input type=\"submit\" name=\"submit\" value=\"Contact\" /> </form>"; include('global/global_footer.php'); }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48273 Share on other sites More sharing options...
High_-_Tek Posted June 22, 2006 Share Posted June 22, 2006 Or you could make it as painless as possible and...use an onSubmit="window.location('url here')" Quote Link to comment https://forums.phpfreaks.com/topic/12585-not-redirecting/#findComment-48351 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.