Sultan Aslam
Sultan Aslam

Reputation: 6238

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>";

        }
    }

    ?>

Upvotes: 0

Views: 423

Answers (1)

Marty
Marty

Reputation: 39456

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)

Upvotes: 1

Related Questions