Jump to content

DaveMag

New Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by DaveMag

  1. I am not a developer but I can modify code to work for me. The following code works on my test machine (Windows 10, IIS, PHP 7.4) but doesn't work on my website (cPanel, Some version of Linux, PHP 7.4). The two dropdowns are for State and City. You are supposed to be able to select the state and then select a city from that state then bring up a report for craft breweries in the city. When selecting State from the first dropdown, the page refreshes, the URL is correct with the reports.php?cat=<STATE> so $cat is being set, but the first dropdown no longer has the state selected and the second dropdown is populated with All cities and not just one ones from the selected state. Any ides why this is working fine on one machine and not the other?

    Selected code from reports.php

    <?php
    $cat=$_REQUEST['cat'];

    ?>
    <SCRIPT language=JavaScript>
        <!--
        function reload(form)
        {
            var val=form.cat.options[form.cat.options.selectedIndex].value;
            self.location='reports.php?cat=' + val ;
        }
            
    </script>


    <?Php
        ///////// Getting the State from Mysql table for first list box//////////
        $Cyquer2="SELECT DISTINCT breweries.State, states.state FROM breweries INNER JOIN states ON breweries.State=states.abbr ORDER BY states.state"; 
        $Cyresult2 = mysqli_query($con, $Cyquer2);

        /////// for second drop down list we will check if State is selected else we will display all the cities///// 
        if(isset($cat) and strlen($cat) > 0) 
        {
            $Cyquer="SELECT DISTINCT City FROM breweries where State='" . $cat . "' order by City"; 
        }
        else 
        { 
            $Cyquer="SELECT DISTINCT City FROM breweries order by City"; 
        } 
        
        $Cyresult1 = $con->query($Cyquer); 

        echo "<form method=post action='brewerylistbycity.php'>";
            //////////        Starting of first drop downlist ///////// -->
            echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select State</option>";
                while($Cynoticia2 = mysqli_fetch_array($Cyresult2))
                {
                    if($Cynoticia2['State']==@$cat)
                    {
                        echo "<option selected value='$Cynoticia2[State]'>$Cynoticia2[state]</option>"."<BR>";

                    }
                    else
                    {
                        echo  "<option value='$Cynoticia2[State]'>$Cynoticia2[state]</option>";
                        
                    }
                }
            echo "</select>";
            echo "</br>";

            //////////        Starting of second drop downlist /////////
            echo "</br>";
            echo "<select name='subcat' selected=''><option value=''>Select City</option>";
                while($Cynoticia = $Cyresult1->fetch_assoc()) 
                {
                    echo  "<option value='$Cynoticia[City]'>$Cynoticia[City]</option>";
                }
            echo "</select></br>";

            //// End Form /////
            echo "<input type=submit value=Submit>";
        echo "</form>";
    ?>
     

     

×
×
  • 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.