Posting a variable

Hi,
Is it possible to post ($_POST) a variable, e.g. ($_POST [$var])?
I have a form on a search page with a drop down list populated from mysql DB. This works fine on the search page, but I want to send the results to another page which queries the same DB and outputs more info. My problem is that I can’t $_POST the results as they are now variables themselves. I assume I have to try extracting the contents of the variable before querying it a second time but am unsure of how to go about this.

Relevant code from Search page:

$query = (“SELECT DISTINCT location FROM monuments ORDER BY location”);
$result = mysqli_query($con, $query);
while ($row = $result->fetch_assoc())
{
$location = $row[‘location’];
echo “<option value=>$location”;
}

Relevant code from Results page:
$recorder= $_POST[‘recorder’];
$type= $_POST[‘type’];
$location= $_POST[‘location’];
$query = (“SELECT * FROM monuments”);
$result = mysqli_query($con, $query);
switch (true)
{
case (!empty($type) && empty($recorder) && empty ($location)):
{
$query = (“SELECT * FROM monuments WHERE type = ‘$type’”);
$result = mysqli_query($con, $query);
echo"Results found for $type";
break;
}
case (empty($type) && empty($recorder) &&empty ($location)):
{
$query = (“SELECT * FROM monuments”);
$result = mysqli_query($con, $query);
echo “Results for all recorded Sites”;
break;
} …
Any help would be greatly appreciated. :smiley:

If you are going to a different page, you can store the value in a session to make it accessibile from the new page, or you can pass it via get.

Many thanks for your reply astonecipher,
If I create a session, does that mean I can use ($_POST [$location] within the session or should the syntax be different?
Apologies for being noobie.

Regards,

Mairt

You would assign the value to a session variable first.

[php]$_SESSION[‘location’] = whatever[/php]

Then access it that way.

Ok astonecipher,

I will try that and will let you know how I get on. It’s late here now so I’ll attempt it tomorrow.

Again, thanks for your help.

M

One last thing, you need to call,
session_start()

Everywhere you want to access the session values

Sponsor our Newsletter | Privacy Policy | Terms of Service