Kryllster Posted July 21, 2010 Share Posted July 21, 2010 $classname = $_POST['class']; // Connect to server and select database. $sql = mysql_connect("$host", "$db_username", "$db_password"); if (!$sql) { die('Could not connect: ' . mysql_error()); exit(); } else{ mysql_select_db("$db_name", $sql)or die("cannot select DB"); } $query = "SELECT * FROM $tbl_name ORDER by Class WHERE Class == $classname"; $result = mysql_query($query) or die (mysql_error()); $num = mysql_num_rows($result); when I run this code I get 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 'WHERE Class == Paladin' at line 1 Not sure where else to go with this? I am running a simple form where the person selects a class from a drop down list and then displays the skill information on that input. Quote Link to comment https://forums.phpfreaks.com/topic/208470-returning-an-error/ Share on other sites More sharing options...
dezkit Posted July 21, 2010 Share Posted July 21, 2010 $query = "SELECT * FROM $tbl_name WHERE Class='".$classname."' ORDER by Class"; Quote Link to comment https://forums.phpfreaks.com/topic/208470-returning-an-error/#findComment-1089298 Share on other sites More sharing options...
freelance84 Posted July 21, 2010 Share Posted July 21, 2010 $query = "SELECT * FROM $tbl_name WHERE Class = '$classname' ORDER by Class "; Quote Link to comment https://forums.phpfreaks.com/topic/208470-returning-an-error/#findComment-1089299 Share on other sites More sharing options...
PFMaBiSmAd Posted July 21, 2010 Share Posted July 21, 2010 The following is the SELECT syntax definition - SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [sTRAIGHT_JOIN] [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT] [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [iNTO OUTFILE 'file_name' [CHARACTER SET charset_name] export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name]] [FOR UPDATE | LOCK IN SHARE MODE]] You must put the parts of it that you use in your query in the order that they are present in syntax definition. A WHERE clause must come before an ORDER BY clause. Quote Link to comment https://forums.phpfreaks.com/topic/208470-returning-an-error/#findComment-1089301 Share on other sites More sharing options...
Kryllster Posted July 21, 2010 Author Share Posted July 21, 2010 Changing the code to that specific order made it work thanks for the info now I know this is something I had never tried before. Quote Link to comment https://forums.phpfreaks.com/topic/208470-returning-an-error/#findComment-1089319 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.