messy Posted August 22, 2009 Share Posted August 22, 2009 Hi - I am sure this is very simple but as I am so new to PHP and working with someone elses code I am just fumbling along at the moment - any help/suggestions would be appreicated - Thanks a mill FIREFOX ERROR WHEN TESTING THE SEARCH FUNCTION 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 'FROM AllData where 1=1 AND AllData.Restaurant = 1' at line 1 CODE - FROM SEARCH RESULTS PAGE <?php require_once('connections/testing.php'); ?> <?php //search value $searchByCounty = $_POST['county']; $searchByCategory = $_POST['category']; mysql_select_db($database_Testing, $Testing); $query_Recordset1 = "SELECT AllData.Restaurant, AllData.Producer, AllData.Cookery_School, AllData.Caterer, AllData.Consultant, AllData.Accomodation, AllData.Patron, AllData.Freelance, AllData.Lecturer, AllData.Name, AllData.Address1, AllData.Address2, AllData.Address3, AllData.County, AllData.Tel, AllData.Fax, AllData.Email, AllData.Website, AllData.Proprietor, AllData.Chef, AllData.Member1, AllData.Location, AllData.Description, AllData.Additional_Info, AllData.Wheelchair_Access, AllData.OH_Lunch, AllData.OH_Dinner, AllData.Closed, FROM AllData where 1=1"; if($searchByCounty !="All" && $searchByCounty !="") { $query_Recordset1 = $query_Recordset1 . " AND AllData.County Like '%" . $searchByCounty . "%'"; } if ($searchByCategory =="Restaurant") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Restaurant = 1"; } else if ($searchByCategory == "Producer") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Producer = 1"; } else if($searchByCategory == "Cookery_School") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Cookery_School = 1"; } else if($searchByCategory == "Caterer") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Caterer = 1"; } else if($searchByCategory == "Consultant") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Consultant = 1"; } else if($searchByCategory == "Accomodation") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Accomodation = 1"; } else if($searchByCategory == "Patron") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Patron = 1"; } else if($searchByCategory == "Freelance") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Freelance = 1"; } else if($searchByCategory == "Lecturer") { $query_Recordset1 = $query_Recordset1 . " AND AllData.Lecturer = 1"; } $Recordset1 = mysql_query($query_Recordset1, $Testing) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> Link to comment https://forums.phpfreaks.com/topic/171393-error-in-my-sql-syntax-can-anyone-help-thanks/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2009 Share Posted August 22, 2009 In sql error messages like - ... for the right syntax to use near 'xxxxx The part of the query that is printed right after the ' is where something was found that could not be understood in the current context. Usually that error means you have used an sql keyword improperly (as a column name or your data is not enclosed in single-quotes so it looks like a column name instead of data...) Looking at the query syntax in the vicinity of that point (the error can be caused by something that comes before where the error was flagged) usually helps find the error. In your case there is an extra comma right before the FROM keyword that implies that FROM should be another item in the list of things being selected. Link to comment https://forums.phpfreaks.com/topic/171393-error-in-my-sql-syntax-can-anyone-help-thanks/#findComment-903949 Share on other sites More sharing options...
Aravinthan Posted August 22, 2009 Share Posted August 22, 2009 AllData.Restaurant, AllData.Producer, AllData.Cookery_School, AllData.Caterer, AllData.Consultant, AllData.Accomodation, AllData.Patron, AllData.Freelance, AllData.Lecturer, AllData.Name, AllData.Address1, AllData.Address2, AllData.Address3, AllData.County, AllData.Tel, AllData.Fax, AllData.Email, AllData.Website, AllData.Proprietor, AllData.Chef, AllData.Member1, AllData.Location, AllData.Description, AllData.Additional_Info, AllData.Wheelchair_Access, AllData.OH_Lunch, AllData.OH_Dinner, AllData.Closed, Remove the last comma But why dont you jsut replace the whole thing by * It will be way simpler. Link to comment https://forums.phpfreaks.com/topic/171393-error-in-my-sql-syntax-can-anyone-help-thanks/#findComment-903952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.