mattyd Posted October 22, 2010 Share Posted October 22, 2010 Hello. I currently have a web page that allows a user to enter text into a form then select a "Submit Query" button; upon doing this the entered text is saved to a database and displayed for the user on the same page (the page where the form and "Submit Query" button are located). My question is as follows: I wish the results to be displayed on a new page when the "Submit Query" button is clicked, not displayed on the same page. Is this achieved through targeting? I am a bit lost at this point on how to achieve this result. Thank-you in advance for any help. ~Matty Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 22, 2010 Share Posted October 22, 2010 do you have any code to show us thus far? Quote Link to comment Share on other sites More sharing options...
mattyd Posted October 22, 2010 Author Share Posted October 22, 2010 do you have any code to show us thus far? Yes. So far I am using the following two files: index.php <?php include 'connection.php'; $query = "SELECT * FROM people"; $result = mysql_query($query) or die(mysql_error()); while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?> <H1>Add a Review:</H1> <form action="create.php" method="post"> <input type="text" name="inputName" value=""/> </br > <textarea cols="50" rows="4" name="inputDesc" value=""/></textarea> </br > <input type= "submit" name= "submit"/> </form> <html> <head></head> <body> <p>The current second is <span style='font-size:16px;font-weight:bold;color:red;position:absolute;right:25px;'><?php echo time(); ?></span> on this computer.</p> </body> </html> connection.php <?php $dbhost = 'mysql7.000webhost.com'; $dbuser = 'a4542527_root'; $dbpass = '*******'; $db = 'a4542527_test1'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); ?> The basic function works fine. I am just trying to figure out how to have the text data returned/displayed to a new page after it is submitted. Thanks, Matty Quote Link to comment Share on other sites More sharing options...
rwwd Posted October 22, 2010 Share Posted October 22, 2010 Right, when you want the detail that has been submitted to appear on another page, this is where the action attribute needs to have a value in it:- <form name="myform" method="POST" action="yourProcessFileHere.php"> then the file (yourProcessFileHere.php in this example) has all of the code that is required to process of the contents of the form being submitted: (contents of this file is something like this:-) <?php //set error reporting to on ;p error_reporting(E_ALL); if(isset($_POST['submit']) && !empty($_POST['submit'])){ //process your data here } else{ //something went wrong redirect user back to the form file/page } ?> Using this method you can effectively 'seperate' your html processing script from the html form file that post's the data - hopefully that makes sense to you. And just to clarify for the example I have used, I have named the submit button 'submit', you could assign it a value and check that that value is there to see that the form has been submitted properly. Have fun. Rw Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 22, 2010 Share Posted October 22, 2010 data from a form can be accessed via $_POST if you want 'preserve' data across several pages, you should look into sessions http://www.tizag.com/phpT/phpsessions.php 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.