Hello, I am new to this site and to php and mySQL...and I need some help. I know this topic is all over the web but after a couple of days of looking and refering to several text books it still doesn't work so please bear with me.

I have created a web page with an associated mySQL database for our local women's golf club. I am trying to create a routine that will allow active members to get a web page displaying a listing of other members who live near them (in the same city/town). I have created a drop-down list in file 1 (memberSelect.php) with the following code below.

I want to pass the the value selected (town) to file 2 (activeMemberListing_NearMe.php) using the POST method. The code in file 2 is as follows below.

The While loop processes query results and displayes all records found. Note - I know this while loop works as it is taken from another file that successfully calls a SELECT statement and simply lists all active members of the club.

When I open file 1, select a city and click the "List Members" button I end up right back at file 1. This leads me to believe that I am passing nothing with the the "IF($cityID == 0)" code line in file 2 being true and thereby returning me to file 1.

I know this is a static selection list but before I move to a dynamic selection list I want to know why this doesn't work. Any help will be greatly appreciated.

Kathy

File 1
<?php

        //  2nd select routine

        echo' <form action="activeMemberListing_NearMe.php" method="post">';
        echo'   <table> <tr> <td>';

        echo'             <select name="town">';
        echo'               <option value="0" name="town" selected="selected">...Select City...</option>';
        echo'                 <option value="Carson City">Carson City</option>';
        echo'                 <option value="Gardnerville">Gardnerville</option>';
        echo'                 <option value="Markleeville">Markleeville</option>';
        echo'                 <option value="Minden">Minden</option>';
        echo'                 <option value="Smith">Smith</option>';
        echo'                 <option value="South Lake Tahoe">South Lake Tahoe</option>';
        echo'                 <option value="Stateline">Stateline</option>';
        echo'                 <option value="Wellington">Wellington</option>';
        echo'                 <option value="Zepher Cove">Zepher Cove</option>';
        echo'             </select>';               
        echo'           </td> <td></td> <td>';
        echo'             <input type="submit" value="List Members" />';
        echo'           </td> </tr> </table>';  
        echo' </form>';

    ?>      

File 2

 if($dbSuccess)
        {
              //  Get the details of the member's form the selected city 
            $cityID = $_POST["town"];   
            if ($cityID == 0) 
             {
                echo "<script type='text/javascript'> document.location = 'memberSelect.php'; </script>";
             }   // end if          

          $activeMembersNearMe_SQLselect = "SELECT FirstName, FullName, Address, City, State, Zip, HomePhone, CellPhone, Email, Picture ";
          $activeMembersNearMe_SQLselect .= "FROM ";
          $activeMembersNearMe_SQLselect .= "members ";
          $activeMembersNearMe_SQLselect .= "WHERE Status = 'Active' AND City = '".$cityID."' ";
          $activeMembersNearMe_SQLselect .= "ORDER BY FirstName , LastName ";

          $activeMembersNearMe_SQLselect_Query = mysqli_query($dbConnected,$activeMembersNearMe_SQLselect); 

          $index = 1;

          while ($row = mysqli_fetch_array($activeMembersNearMe_SQLselect_Query))

Kathy, when you submit via post, the values are being sent as strings. So in File 2, change the line if($cityID == 0) to if($cityID == "0"). When testing code like this, I would recommend changing the redirect to a printout of the posted value. That method has helped me track down many problems. If you do that before changing the line, you'll see that no matter what value is passed, it's evaluating as true even though the posted value is clearly not 0. According to the php documentation on comparison types, this comparison ("string" == 0) will cast the string as an integer, which will always be 0 unless the string starts with a number. Hope that helps, comparisons can be confusing.

Hi Kathy,

How I would debug this is to putvar_dump($_POST);exit; at the top of file 2 so you can see what is actually being sent.

Also with a redirect it is best to do it within PHP not with javascript: header("Location: http://www.example.com/");exit;

Javascript is client-side so the user can disable it but inside php its fully under your control.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.