简体   繁体   中英

How to check for 'All' cases in select option statement

I have a problem in my code that maybe someone can check and point out the problem. I'm creating two webpages in php and I'm requesting variables from one page to another. As you see in the photo in my first page I have a drop list of values I successfully grab from a database. In the second page I want to print a list of matching items which are boats based on the choice the user select from the first page. Now from there I creating a sql query to first check that the user is not selected 'All' or not mixing 'All' with the provided choices. If either is not the case then the database field name is equal to the requested item and echo that to the screen. In second page I have successfully connected to the database. The problem is when testing my code, the screen is blank which means, my string is faulty. Thanks in advance. Here is my code

From what I can see here you're continuously overwriting the value of sqlStr instead of adding to it.

And you're missing $ before sqlStr

Try:

$sqlStr = "SELECT * FROM boats  Where";

if($boatClass == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'Class' = $boatClass;
}
if($boatMake == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'Make' = $boatMake;
}
if($Year == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'Year' = $Year;
}
if($used == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'UsedOrNew' = $used;
}

A blank page means you have parsing errors. If you are working on a dev machine only, you can change the php.ini to display errors. By default it is off for security reasons.

Or you can check the error log, it gets populated every time a script with errors in it is run.

To find where your log file is, run a phpinfo script: http://php.net/manual/pt_BR/function.phpinfo.php and check for error_log.

If it is blank, then default locations for error log file:

linux + nginx is: /var/log/nginx/error.log
linux + apache is: /var/log/apache/error.log
Windows is likely to be in path/to/php/log/error-something.txt

Hope this helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM