$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'
..AND `users`.`name`='$name'
– Riadname
? – Wasiq Muhammad