zero_ZX Posted December 3, 2009 Share Posted December 3, 2009 Hi i have this code: $iteminfo = mysql_query("SELECT desc FROM wc_items WHERE itemid = '$_GET[id]'") or die(mysql_error()); And it gives me 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 'desc FROM wc_items WHERE itemid = '103'' at line 1 What could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/ Share on other sites More sharing options...
YourNameHere Posted December 3, 2009 Share Posted December 3, 2009 Hi i have this code: $iteminfo = mysql_query("SELECT desc FROM wc_items WHERE itemid = '$_GET[id]'") or die(mysql_error()); And it gives me 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 'desc FROM wc_items WHERE itemid = '103'' at line 1 What could be wrong? try $iteminfo = mysql_query("SELECT `desc` FROM `wc_items` WHERE itemid = '{ $_GET['id'] }'") or die(... Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970315 Share on other sites More sharing options...
zero_ZX Posted December 3, 2009 Author Share Posted December 3, 2009 Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\***\item.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970558 Share on other sites More sharing options...
cags Posted December 3, 2009 Share Posted December 3, 2009 What does your code look like now? Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970561 Share on other sites More sharing options...
jcombs_31 Posted December 3, 2009 Share Posted December 3, 2009 Is desc a value in your table? Maybe because that is a mysql keyword for sorting. Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970565 Share on other sites More sharing options...
Maq Posted December 3, 2009 Share Posted December 3, 2009 It's hard to tell you whats wrong without line 19 and some of the surrounding code. [ot]@Zero_ZX, One should not deal with MySQL errors in that manner. They should be handled appropriately. If a mysql_query returns false, you should throw an exception or display some sort of error message, but not kill the script.[/ot] Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970604 Share on other sites More sharing options...
zero_ZX Posted December 3, 2009 Author Share Posted December 3, 2009 Is desc a value in your table? Maybe because that is a mysql keyword for sorting. Yes, It's a text table and says "something here" Whole code: <?php session_start(); // dBase file include "inc/config.php"; if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page Header("Location: login.php"); } if ($_GET["id"] == "0") { die ("When The item ID is 0 it means that you do not have an item equipped here."); } else $iteminfo = mysql_query("SELECT `desc` FROM `wc_items` WHERE itemid = '{ $_GET['id'] }'") or die(mysql_error()); // keeps getting the next row until there are no more to get while($item = mysql_fetch_array( $iteminfo )) { echo "<table border='1'>"; echo "<tr><td><strong>Item ID:</strong></td>"; echo "<td>"; echo "'$_GET[id]'"; echo "</td></tr>"; echo "<tr><td><strong>Description:</strong></td>"; echo "<td>"; echo "".$item['desc'].""; echo "</td></tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970656 Share on other sites More sharing options...
YourNameHere Posted December 4, 2009 Share Posted December 4, 2009 You should consider changing that column name to something else as "desc" is a SQL reserved word. the `` will fix it but it's not best practice. That is prolly your issue. Quote Link to comment https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-971085 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.