travelkind Posted October 28, 2009 Share Posted October 28, 2009 I was trying to run a simple script and have received the following 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 '.duns_num = custmast.duns_num' at line 1 My server is hosted so I went and checked the version and here is what it says: Server version: 5.0.67.d7-ourdelta-log Here is my simple code: <?php $dbhost = "xxxxx"; $dbuser = "xxxxx"; $dbpassword = "xxxxx"; $dbdatabase = "ccfee"; $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); // Make a MySQL Connection // Construct our join query $query = "SELECT sunocoimport.duns_num, custmast.fee_percent". "FROM sunocoimport, custmast". "WHERE sunocoimport.duns_num = custmast.duns_num"; $result = mysql_query($query)or die(mysql_error()); // Print out the contents of each row into a table while($row = mysql_fetch_array($result)){ echo $row['Duns_num']."-".$row['Fee_percent']; echo "<br />"; } ?> Does anyone have any clue? Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/ Share on other sites More sharing options...
Alex Posted October 28, 2009 Share Posted October 28, 2009 Is there any reason you're concatenating strings with other strings? The problem could be because you query looks like this: SELECT sunocoimport.duns_num, custmast.fee_percentFROM sunocoimport, custmastWHERE sunocoimport.duns_num = custmast.duns_num try: $query = "SELECT sunocoimport.duns_num, custmast.fee_percent FROM sunocoimport, custmast WHERE sunocoimport.duns_num = custmast.duns_num"; Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945959 Share on other sites More sharing options...
travelkind Posted October 28, 2009 Author Share Posted October 28, 2009 Thanks for your response. I tried your modifications and I got where "-" signs all the way down the left hand side of my screen like: - - - - - Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945965 Share on other sites More sharing options...
Alex Posted October 28, 2009 Share Posted October 28, 2009 Well that solves your SQL syntax problem. The other issue is because of this line: echo $row['Duns_num']."-".$row['Fee_percent']; Apparently in all the records you fetched the rows (if they even exist) Duns_num and Fee_percent are empty. Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945968 Share on other sites More sharing options...
travelkind Posted October 28, 2009 Author Share Posted October 28, 2009 I checked my database and those fields all have a "0" in each one. I will populate them with a number and run the script again. Thanks a lot for your help! Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945974 Share on other sites More sharing options...
travelkind Posted October 28, 2009 Author Share Posted October 28, 2009 Okay I added some data into the duns_num and fee_percent but it still came back with the "-" (minus sign). Maybe I should clear all my data in the database and reimport it? Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945979 Share on other sites More sharing options...
Alex Posted October 28, 2009 Share Posted October 28, 2009 There's no need for that. Just make sure that your rows are named exactly 'Duns_num' and 'Fee_percent'. Edit: Just realized in your query it's lower-case, is it all lower-case in the database? If so use this line: echo $row['duns_num']."-".$row['fee_percent']; If it's not all lower-case in your database then just change your query. Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945982 Share on other sites More sharing options...
travelkind Posted October 28, 2009 Author Share Posted October 28, 2009 I don't know if capitalization matters or not. They are labeled: 'duns_num' and 'fee_percent' Your comment asked if they were: 'Duns_num' and 'Fee_percent' Does this matter? Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945983 Share on other sites More sharing options...
Alex Posted October 28, 2009 Share Posted October 28, 2009 Yes it does matter. It should match in all 3 locations: The database, the query, and when grabbing the row from the $row array. Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945984 Share on other sites More sharing options...
travelkind Posted October 28, 2009 Author Share Posted October 28, 2009 Brilliant! It worked! I had it capitalized in the "grabbing". Thank you very much for your help! As you can tell, I am VERY new to this! Quote Link to comment https://forums.phpfreaks.com/topic/179293-solved-error-in-your-sql-syntax-check-server-version/#findComment-945989 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.