0
$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";
}
一切都確定了$type
,$flightdate
,$seat
但如果我輸入$name
,它給error.e.g如果我輸入ABC,它提供了以下。用戶表中有一列name
。MySQL錯誤未知列「ABC」
異常(數據庫異常) 'YII \分貝\異常' 與消息 「SQLSTATE [42S22]:柱未找到:1054未知列 '' 在 '其中正在執行條款' 的SQL ABC是:SELECT * FROM book_seat INNER JOIN座椅ON book_seat.seat_id = seat.seat_id INNER JOIN用戶ON book_seat.user_id = users.user_id WHERE 1 = 1 AND users.name = ABC」
將名稱變量放在單引號中,因爲它是一個字符串 –
在用戶表中有''AND \'''''''''''''''''''' – Riad
' name'? –