2016-04-01 50 views
0

1054的問題,我得到這個錯誤:柱未發現:在MySQL

Column not found: 1054 

對於下面的代碼:

$username=$_SESSION['username']; 
$status="active"; 
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
// run query to select records 
$stmt = $db->prepare("SELECT * FROM job INNER JOIN employer ON job.eid= employer.eid WHERE employer.username=$username AND job.status=active "); 
$stmt->execute(); 

我有兩個表,jobsemployer。我加入這兩個表並獲得結果基於usernamestatus

+0

'$ username'是一個字符串。缺少'''s。 'employer.username ='$ username''和'job.status ='active''。 –

回答

0

您應該將變量$ username放在引號內。

$stmt = $db->prepare("SELECT * FROM job INNER JOIN employer ON job.eid= employer.eid WHERE employer.username = '".$username."' AND job.status= 'active'"); 

希望這會有所幫助。