0
votes
  $sql="SELECT * FROM book_seat INNER JOIN seat ON book_seat.seat_id=seat.seat_id
                                INNER JOIN users ON book_seat.user_id=users.user_id
                                WHERE 1=1";
            if($type)
            {
               $sql.= " AND seat.type=$type";    
            }

            if($name)
            {
               $sql.= " AND users.name=$name";    
            }

            if($flightdate)
            {
                $sql.= " AND book_seat.date_booked=$flightdate";
            }

            if($seat)
            {
                $sql.=" AND seat.seat=$seat";
            }

Everything is ok with $type, $flightdate ,$seat but if i input $name, it gives error.e.g if i input abc, it gives the following. There is a column name in users table.

Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'abc' in 'where clause' The SQL being executed was: SELECT * FROM book_seat INNER JOIN seat ON book_seat.seat_id=seat.seat_id INNER JOIN users ON book_seat.user_id=users.user_id WHERE 1=1 AND users.name=abc'

1
Put the name variable in single quotes as it is a stringRanit Das
use backtick like ..AND `users`.`name`='$name'Riad
in users table have you a column with name?Wasiq Muhammad
thank you all. @RanitDasmicky

1 Answers

0
votes

Try this

AND `users`.`name`='$name'