Jump to content

Php mysql - select?


zero_ZX

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/183827-php-mysql-select/
Share on other sites

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(... 

Link to comment
https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970315
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970604
Share on other sites

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>";	
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/183827-php-mysql-select/#findComment-970656
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.