Author Topic: Posting a variable  (Read 246 times)

mairt

  • New Member
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
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</option>";               
         }

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 <span class='recorded'>$type</span>";
        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.  :D

PHP Help Forum

Posting a variable
« on: July 16, 2017, 11:01:41 am »



PHP Help Forum

Re: Posting a variable
« Reply #1 on: July 16, 2017, 04:31:51 pm »



PHP Help Forum

Re: Posting a variable
« Reply #2 on: July 16, 2017, 05:42:21 pm »


astonecipher

  • Software Engineer
  • Professional PHP Helper
  • Senior Member
  • *
  • Posts: 2437
  • Karma: 95
    • View Profile
Questions? Go here first.
http://www.phptherightway.com/

PHP Help Forum

Re: Posting a variable
« Reply #3 on: July 16, 2017, 06:11:48 pm »



PHP Help Forum

Re: Posting a variable
« Reply #4 on: July 16, 2017, 06:19:31 pm »



PHP Help Forum

Re: Posting a variable
« Reply #5 on: July 16, 2017, 06:21:31 pm »



PHP Help Forum

Re: Posting a variable
« Reply #6 on: August 05, 2017, 03:27:55 am »