简体   繁体   中英

Mysqli Where Clause Error

When i use single where clause like WHERE source_city = '$to_name' , it work fine but when add another check it show me error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result

    <?php  
        if(isset($_GET["view"])){
            $to_name = $_GET["to_name"];
            $from_name = $_GET["from_name"];
            $select_user = "SELECT * from citi 
                WHERE source_city = '$to_name' AND
                dest_city = '$from_name'";
            $run_user = mysqli_query($conn,$select_user);
            if(!$run_user){
                echo "Error!";
            }
            while ($row=mysqli_fetch_array($run_user)){
            $id = $row[0];
            $source_name = $row[1];
            $dest_name = $row[2];
            echo "
                    <br><br>
                    $id<br>
                    $source_name<br>
                    $dest_name<br>";

        }
    }

    ?>

The correct syntax for muliple WHERE statements is:

WHERE condition1 AND condition2 AND condition3

Using OR for completeness:

WHERE (condition1 AND condition2) OR (condition3 AND condition4)

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