dmccabe Posted December 20, 2008 Share Posted December 20, 2008 I had an SQL statement that was working fine, I added a new field to the table and made it the primary key, now my SQL statement shows 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 'SORT BY `REG` ASC' at line 1 Here is the code: $make_id = $_POST['MAKE_ID']; $model_id = $_POST['MODEL_ID']; $colour_id = $_POST['COLOUR_ID']; $status_id = $_POST['STATUS_ID']; $location_id = $_POST['LOCATION_ID']; $fueltype_id = $_POST['FUELTYPE_ID']; $transmissiontype_id = $_POST['TRANSMISSIONTYPE_ID']; $where = "WHERE "; $where .= (isset($make_id) && !empty($make_id))?"`make_id` = '" . $make_id. "' AND ":''; $where .= (isset($colour_id) && !empty($colour_id))?"`colour_id` = '" . $colour_id. "' AND ":''; $where .= (isset($model_id) && !empty($model_id))?"`model_id` = '" . $model_id. "' AND ":''; $where .= (isset($status_id) && !empty($status_id))?"`status_id` = '" . $status_id. "' AND ":''; $where .= (isset($location_id) && !empty($location_id))?"`location_id` = '" . $location_id. "' AND ":''; $where .= (isset($fueltype_id) && !empty($fueltype_id))?"`fueltype_id` = '" . $fueltype_id. "' AND ":''; $where .= (isset($transmissiontype_id) && !empty($transmissiontype_id))?"`transmissiontype_id` = '" . $transmissiontype_id. "' AND ":''; $where = substr($where, 0, -4); $query = "SELECT * FROM `tbl_vehicles` " . $where . " SORT BY `REG` ASC"; echo "$query <br />"; When I echo out the value of $query I get: SELECT * FROM `tbl_vehicles` WHERE `make_id` = '1' AND `model_id` = '3' SORT BY `REG` ASC Everything looks right, but I dont know why I am getting the error? Link to comment https://forums.phpfreaks.com/topic/137799-solved-added-a-new-field-to-a-table-now-my-sql-statement-gives-error/ Share on other sites More sharing options...
dmccabe Posted December 20, 2008 Author Share Posted December 20, 2008 Found it !!! lol "SORT BY" should be "ORDER BY" lol ooops Link to comment https://forums.phpfreaks.com/topic/137799-solved-added-a-new-field-to-a-table-now-my-sql-statement-gives-error/#findComment-720256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.