Jump to content

Database connection and query in background.


synking

Recommended Posts

Hey guys. 

 

  Wondering if you people could give me some help on a procedural problem i am having.

 

I want to display information from a database.  What i am hoping to do is process all of the query and connection in the background.

 

 

He is how i am doing this.

 

there is a form that submits to the process page with post variables.  and in that page there is a few switch statements that change the query and based on that change forwards them to a different page to display the result but the connection and variable name are not being forwarded so the table never gets processed.

 

It is all done in an if statement and switch statemenst  any ideas on how to do this properly.  I think i am just confused on the procedure of it all.

Link to comment
Share on other sites

How are you "forwarding" from the processing page to the display page? You shouldn't be forwarding the user and in stead should have separate scripts to break up the functionality and INCLUDE the scripts. I'm guessing you are doing a header() redirect or something similar which wipes out any post data.

 

Here is an example of one way:

 

process_page.php

//Do some validation to ensure you have the necessary info to actually do the processing
if(!isset($_POST['foo'])
{
    echo "Error: Unable to process your request";
}
else
{
    include('get_data_page.php');
    if(!$result)
    {
        echo "Error: unable to get data<br>" . mysql_error();
    }
    else
    {
        include('display_page');
    }
}

 

get_data_page.php

//Create/run query
$fooVar = mysql_real_escape_string($_POST['foo']);
$query = "SELECT * FROM table WHERE foo = '$fooVar'";
$result = mysql_query($query);

 

display_page.php

while($row = mysql_fetch_assoc($result)
{
    //Create output
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.