abch624 Posted July 4, 2008 Share Posted July 4, 2008 Hi Guys, I have a problem here that gives me this error 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 '%Zahid%' at line 1 Now the code that searches produces this is <?php $tbl_personal="personaldetails"; // Table name for personal details $tbl_profile="profiledetails"; // Table name for profile details $tbl_cities="tblcities"; // Table name for city name $tbl_countries="tblcountries"; // Table name for country name $tbl_branches="tblbranches"; // Table name for branch name $tbl_hidden="hidden"; // Table name for hidden values // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //Variable from url $query = $_GET['query']; // Variables sent from form $searchfield=$_POST['searchField']; echo $sql = "SELECT DISTINCT P.firstName, P.lastName, P.bid, P.lid, D.profilePicture FROM $tbl_personal P JOIN $tbl_profile D ON (P.profileDetailsID = D.profileDetailsID) JOIN $tbl_cities C ON (P.lid = C.lid) JOIN $tbl_branches B ON (P.bid = B.bid) WHERE P.firstName LIKE %$query%"; echo "<hr>"; if ($result = mysql_query($sql)) { $row=mysql_fetch_array($result); $lastname = $row['lastName']; $profilepicture = $row['profilePicture']; } else { echo mysql_error(); } ?> I echo the sql statement and I get SELECT DISTINCT P.firstName, P.lastName, P.bid, P.lid, D.profilePicture FROM personaldetails P JOIN profiledetails D ON (P.profileDetailsID = D.profileDetailsID) JOIN tblcities C ON (P.lid = C.lid) JOIN tblbranches B ON (P.bid = B.bid) WHERE P.firstName LIKE %Zahid% This means the sql statement is perfectly fine... I would like to know the correct syntax I should use inorder to use the "LIKE %text%" Please help. Thanks - Zahid Link to comment https://forums.phpfreaks.com/topic/113268-solved-php-sql-sytanx-error-near-like/ Share on other sites More sharing options...
DarkWater Posted July 4, 2008 Share Posted July 4, 2008 You forgot ' ' around the string. LIKE '%Zahid%' Link to comment https://forums.phpfreaks.com/topic/113268-solved-php-sql-sytanx-error-near-like/#findComment-581955 Share on other sites More sharing options...
abch624 Posted July 4, 2008 Author Share Posted July 4, 2008 Thanks m8 Thats was silly of me.. thanks Link to comment https://forums.phpfreaks.com/topic/113268-solved-php-sql-sytanx-error-near-like/#findComment-581956 Share on other sites More sharing options...
DarkWater Posted July 4, 2008 Share Posted July 4, 2008 No problem. Link to comment https://forums.phpfreaks.com/topic/113268-solved-php-sql-sytanx-error-near-like/#findComment-581957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.