Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts

    form processing and viewing results

    I have a page1.php which contains a post form and a page2.php which displays results. I have a seperate php script file that processes the form data and queries the database. What is the best, most efficient way of processing? Once the php script finishes querying the database, I would end up with, assuming the query returns a result,
    PHP Code:
    while($result mysql_fetch_assoc($query)) 
    how do I get the data to the display page? Looking for examples I found one approach which is to have a go-between file which looks like this:
    PHP Code:
    <?PHP 
    include_once(process.php);
    process($_POST);
    display_results;
    ?>
    Can someone explain the display_results part? Is this a form of redirect? Any words of wisdom appreciated.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Why not display the results from the db query from the processing page? You don't need to have separate pages for processing form data and displaying the processed results

    eg

    PHP Code:
    <?php
        $title 
    $_POST['txtTitle'];
        
    $query 'select title from books where title like "'.$title.'"';
        
    $rs mysql_query($query$conn);
        while(
    $row=mysql_fetch_assoc($rs)) {
             echo 
    $row['title'].'<br />';
        }
        
    mysql_free_result($rs);
    ?>
    Using include() simply inserts the code in the include file into your script as if it was written there originally.
    Code:
    include_once(process.php); 
    
    Last edited by bullant; 03-02-2011 at 12:15 PM.

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So if I'm connecting to a database in process.php, I have
    PHP Code:
    $host 'localhost';
    $user 'username';
    $password 'whatever'
    Do I list these in a seperate file?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •