View Full Version : form processing and viewing results

03-02-2011, 11:52 AM
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,

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:

Can someone explain the display_results part? Is this a form of redirect? Any words of wisdom appreciated.

03-02-2011, 01:12 PM
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


$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 />';

Using include() simply inserts the code in the include file into your script as if it was written there originally.


03-02-2011, 02:12 PM
So if I'm connecting to a database in process.php, I have

$host = 'localhost';
$user = 'username';
$password = 'whatever';
Do I list these in a seperate file?