joomphp Posted February 15, 2011 Share Posted February 15, 2011 I am running a simple php mysql_connect but I keep on getting the following error: Connected to MySQL 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 'FROMÂ jos_menu' at line 1 I don't understand what the issue is here, teh syntax seems to be correct but there is something wrong with the mysql_query. Can anyone spot the issue here and please help. This query was running fine before. I have tried this on my godaddy account (linux) and also on my local machine which is using xampp on windows xp. I keep on gettnig the same error. Below is my code please help! <?php $username = "myname"; $password = "pwd"; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die ('Error: '.mysql_error ()); echo "Connected to MySQL<br>"; mysql_select_db("dbname", $dbhandle); $result = mysql_query("SELECT * FROM jos_menu") or die ('Error: '.mysql_error ()); while ($row = mysql_fetch_array( $result )) {echo $row['parent_id']; } mysql_close($dbhandle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/227747-mysql_query-syntax-error-database-connection/ Share on other sites More sharing options...
joomphp Posted February 15, 2011 Author Share Posted February 15, 2011 Please help! this appears to be simple coding, I just can't believe that I am not seeing where the fault in this is. Quote Link to comment https://forums.phpfreaks.com/topic/227747-mysql_query-syntax-error-database-connection/#findComment-1174585 Share on other sites More sharing options...
kenrbnsn Posted February 15, 2011 Share Posted February 15, 2011 It looks like you have a non-ASCII character in your query. Retype the query. Ken Quote Link to comment https://forums.phpfreaks.com/topic/227747-mysql_query-syntax-error-database-connection/#findComment-1174613 Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 (In the future, please use tags when posting code) Quote Link to comment https://forums.phpfreaks.com/topic/227747-mysql_query-syntax-error-database-connection/#findComment-1174625 Share on other sites More sharing options...
joomphp Posted February 15, 2011 Author Share Posted February 15, 2011 suer thing maq, didn't know about that code thing before. Just wanted to thank kenrbnsn , retyping the code has solved the issue, I don't know how you picked that up, but it worked and the non-ascii was the cause. I am new to php, is there a light weight utility that I can use to type code in so in the future this type of error can be avoided. Thanks so much for your help Quote Link to comment https://forums.phpfreaks.com/topic/227747-mysql_query-syntax-error-database-connection/#findComment-1174629 Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 There are a multitude of reasons this could have happened. You could have CnP, edited with different editors, etc... Quote Link to comment https://forums.phpfreaks.com/topic/227747-mysql_query-syntax-error-database-connection/#findComment-1174645 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.