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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.