我有一個帶內連接的select查詢。我嘗試在phpmyadmin中工作正常。但是,當我在瀏覽器中嘗試它時,它會顯示以下錯誤消息:用php內連接瀏覽器顯示語法錯誤
您的SQL語法錯誤;檢查手冊中 對應於你的MySQL服務器版本正確的語法使用 接近第1行
member_search.php
/default message on top of the result display
$querySrting="WHERE registered_date!='' ORDER BY registered_date ASC ";
$queryMSG="Showing newest to oldest memebrs by default";
///IF STATMENT TO DISTINGOUICH SEARCHING
if(isset($_POST['listbyq']))
{
if($_POST['listbyq']=="newest_members")
{
$querySrting="WHERE registered_date!='' ORDER BY registered_date DESC " or die(mysql_error());
$queryMSG="Showing senior to oldest memebrs";
}
elseif($_POST['listbyq']=="by_specialization")
{
$querySrting="SELECT specialization_name FROM members u
INNER JOIN specialization s
ON u.specialization=s.specialization_id";
$result = mysql_query($querySrting) or die(mysql_error());
$queryMSG="showing members with specs";
}
elseif($_POST['listbyq']=="by_firstname")
{
$fname = $_POST['fname'];
$fname = stripcslashes($fname);
$fname = strip_tags($fname);
$querySrting="WHERE first_name LIKE '%$fname%'"or die(mysql_error());
$queryMSG="Showing member with the name you searched for";
}
}
///******query the member data using the queryString*******//
$sql = mysql_query("SELECT user_id, first_name, last_name, birth_date, specialization, registered_date FROM members $querySrting") or die(mysql_error());
//**********************outputlist*********************************//
$outputlist="";
while($row = mysql_fetch_array($sql))
{
$id=$row['user_id'];
$firstname=$row['first_name'];
$lastname=$row['last_name'];
$birthdate=$row['birth_date'];
$spec = $row['specialization'];
$registereddate=$row['registered_date'];
////***********for the upload image*************************//
$check_pic="members/$id/image01.jpg";
$default_pic="members/0/image01.jpg";
if(file_exists($check_pic))
{
$user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
}
else
{
$user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
}
$outputlist.='
<table width="100%">
<tr>
<td width="23%" rowspan="3"><div style="height:120px;overflow:hidden;"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$id.'" target="_blank">'.$user_pic.'</a></div></td>
<td width="14%"><div align="right">Name:</div></td>
<td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$id.'" target="_blank">'.$firstname.' '.$lastname.'</a></td>
</tr>
<tr>
<td><div align="right">Birth date:</div></td>
<td>'.$birthdate.'</td>
</tr>
<tr>
<td><div align="right">Registered:</div></td>
<td>'.$registereddate.'</td>
</tr>
<tr>
<td><div align="right">His Job:</div></td>
<td>'.$spec.'</td>
</tr>
</table>
<hr />
';
}//close while
你有一個SQL語法錯誤。向我們展示一段PHP代碼是毫無意義的。向我們顯示導致語法錯誤的實際查詢。 – 2013-05-13 17:32:58
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – rekire 2013-05-13 17:42:18