Note that there are some explanatory texts on larger screens.

plurals
  1. POselect query not working
    primarykey
    data
    text
    <p>I have a select query used with php and inner Join but the browser displays an error :</p> <blockquote> <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT specialization_name FROM user u INNER JOIN spe' at line 1</p> </blockquote> <p>Can anyone help me ?</p> <h1>This is the query :</h1> <pre><code>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 user u INNER JOIN specialization s ON u.specialization=s.specialization_id WHERE u.user_id='$id'"; $result = mysql_query($queryString) 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, registered_date FROM user $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="&lt;img src=\"$check_pic\"width=\"120px\"/&gt;"; } else { $user_pic="&lt;img src=\"$default_pic\"width=\"120px\"/&gt;"; } $outputlist.=' &lt;table width="100%"&gt; &lt;tr&gt; &lt;td width="23%" rowspan="3"&gt;&lt;div style="height:120px;overflow:hidden;"&gt;&lt;a href = "http://localhost/newadamKhoury/profile.php?user_id='.$id.'" target="_blank"&gt;'.$user_pic.'&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;td width="14%"&gt;&lt;div align="right"&gt;Name:&lt;/div&gt;&lt;/td&gt; &lt;td width="63%"&gt;&lt;a href = "http://localhost/newadamKhoury/profile.php?user_id='.$id.'" target="_blank"&gt;'.$firstname.' '.$lastname.'&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div align="right"&gt;Birth date:&lt;/div&gt;&lt;/td&gt; &lt;td&gt;'.$birthdate.'&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div align="right"&gt;Registered:&lt;/div&gt;&lt;/td&gt; &lt;td&gt;'.$registereddate.'&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;hr /&gt; '; }//close while ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta name="keywords" content="" /&gt; &lt;meta name="description" content="" /&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Search_Members&lt;/title&gt; &lt;link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' /&gt; &lt;link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' /&gt; &lt;link href="default.css" rel="stylesheet" type="text/css" media="all" /&gt; &lt;!--[if IE 6]&gt; &lt;link href="default_ie6.css" rel="stylesheet" type="text/css" /&gt; &lt;![endif]--&gt; &lt;/head&gt; &lt;body&gt; &lt;?php require_once('header.php'); ?&gt; &lt;div id="wrapper"&gt; &lt;div id="page-wrapper"&gt; &lt;div id="page"&gt; &lt;div id="wide-content"&gt; &lt;table width="94%" height="63"&gt; &lt;tr&gt; &lt;td width="29%"&gt;&lt;form id="form1" method="post" action="member_search.php"&gt; Browse Newest Members &lt;input type="submit" name="button" id="button" value="go" /&gt; &lt;input type="hidden" name="listbyq" value="newest_members" /&gt; &lt;/form&gt;&lt;/td&gt; &lt;td width="28%"&gt;&lt;form id="form2" name="form2" method="post" action="member_search.php"&gt; Search By specialization&lt;br /&gt; &lt;select name="specialization" class="formField"&gt; &lt;option value="0"&gt;-- Select Your Specialization --&lt;/option&gt; &lt;?php specializationQuery(); ?&gt; &lt;/select&gt; &lt;input type="submit" name="button2" id="button2" value="go" /&gt; &lt;input type="hidden" name="listbyq" value="by_specialization" /&gt; &lt;/form&gt;&lt;/td&gt; &lt;td width="43%"&gt;&lt;form id="form3" name="form3" method="post" action="member_search.php"&gt; Search By firstname &lt;label&gt; &lt;input type="text" name = "fname" id="fname" /&gt; &lt;/label&gt; &lt;input type="submit" name="button3" id="button3" value="go" /&gt; &lt;input type="hidden" name="listbyq" value="by_firstname" /&gt; &lt;/form&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;table width="70%" align="center"&gt; &lt;tr&gt; &lt;td&gt;&lt;?php print "$queryMSG"; ?&gt; &lt;br /&gt; &lt;?php print "$outputlist"; ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload