mysql - inner join with php the browser display a syntax error -
this question has answer here:
i have select query inner join. try in phpmyadmin works fine. when try in browser display error message:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'select s.specialization_name user u inner jo' @ line 1
member_search.php
/default message on top of result display $querysrting="where registered_date!='' order registered_date asc "; $querymsg="showing newest oldest memebrs default"; ///if statment distingouich searching if(isset($_post['listbyq'])) { if($_post['listbyq']=="newest_members") { $querysrting="where registered_date!='' order registered_date desc " or die(mysql_error()); $querymsg="showing senior oldest memebrs"; } elseif($_post['listbyq']=="by_specialization") { $querysrting="select specialization_name members u inner join specialization s on u.specialization=s.specialization_id"; $result = mysql_query($querysrting) or die(mysql_error()); $querymsg="showing members specs"; } elseif($_post['listbyq']=="by_firstname") { $fname = $_post['fname']; $fname = stripcslashes($fname); $fname = strip_tags($fname); $querysrting="where first_name '%$fname%'"or die(mysql_error()); $querymsg="showing member name searched for"; } } ///******query member data using querystring*******// $sql = mysql_query("select user_id, first_name, last_name, birth_date, specialization, registered_date 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 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
$querysrting
variable. should concatenate strings:
$sql = mysql_query("select user_id, first_name, last_name, birth_date, specialization, registered_date members $querysrting") // here
should this:
$sql = mysql_query("select user_id, first_name, last_name, birth_date, specialization, registered_date members".$querysrting) // here
Comments
Post a Comment