lucy Posted August 5, 2009 Share Posted August 5, 2009 How can i direct my users to a webpage once a form has been completed? I cant figure it out, i can only get it to echo text back on a white background. here is the script, which is called by the form once submit is clicked: <? $user="n-web171-sau1"; //specially created username $password="jackie01"; $database="web171-netlink"; //connect to the database $con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error()); //select the database mysql_select_db($database, $con); //insert data into database mysql_query("INSERT INTO customer (title, fname, sname, add1, add2, county, pc, email) VALUES ('$_POST[title]','$_POST[fname]','$_POST[sname]','$_POST[add1]','$_POST[add2]','$_POST[county]','$_POST[pc]', '$_POST[email]')") or die('Error: ' . mysql_error()); //close connection mysql_close(); ?> the form itself is a php file, which is included in the main webpage (newcustomerform.php): <form action="php/newcustomerscript.php" method="post"> <p>Title: <input type="text" name="title" tabindex="1"/> </p> <p>Forename: <input type="text" name="fname" id="fname" tabindex="2" /> </p> <p>Surname: <input type="text" name="sname" id="sname" tabindex="3" /> </p> <p> Address line 1: <input type="text" name="add1" id="add1" tabindex="4" /> </p> <p>Address line 2: <input type="text" name="add2" id="add2" tabindex="5" /> </p> <p>County: <input type="text" name="county" id="county" tabindex="6" /> </p> <p>Postcode: <input type="text" name="pc" id="pc" tabindex="7" /> </p> <p>Email: <input type="text" name="email" id="email" tabindex="8" /> </p> <p> <input type="reset" name="clear" id="clear" value="Reset" /> <input type="submit" name="submit" id="submit" value="Submit" /> </p> <p> </p> </form> and the actual webpage itself: <body> <?php include("php/header.php"); ?> <div id="content"> <?php include("php/newcustomerform.php"); ?> </div> </body> Thanks Lucy Quote Link to comment Share on other sites More sharing options...
kickstart Posted August 5, 2009 Share Posted August 5, 2009 Hi You use:- header('Location:SomeWebPage.php'); However you can only use this if you have output nothing to the screen already (not even a blank link before the first <?php ). All the best Keith Quote Link to comment Share on other sites More sharing options...
lucy Posted August 5, 2009 Author Share Posted August 5, 2009 I have not outputted anything to the screen, it just automatically goes to a blank white screen, therefore i could use this? do i need to include the Location part i.e. header('Location:http://www.google.com/'); would be fine? Quote Link to comment Share on other sites More sharing options...
kickstart Posted August 5, 2009 Share Posted August 5, 2009 Hi Yes you can use it. However looking at your current code the reason you are getting a blank page is because you are not outputting anything (unless there is an error). All the best Keith Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted August 5, 2009 Share Posted August 5, 2009 I would use header("Location: http://www.google.com/") not header('Location:http://www.google.com/') IE can tend to be picky if you don't use double quotes with a space between location: and the redirect page/location Quote Link to comment Share on other sites More sharing options...
lucy Posted August 5, 2009 Author Share Posted August 5, 2009 Thanks a lot for your help now onto validation! 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.