Jump to content

[SOLVED] Unknown column '38' in 'where clause'


mike12255

Recommended Posts

Im trying to query my database using the following code:

 

<?php
include ("connect.php");
$id = $_GET['id'];
$id = mysql_real_escape_string($id);

//$sql = "SELECT * FROM tbl_product WHERE pd_id = $'id'";

$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$id'";



$result = mysql_query ($sql) or die (mysql_error());
$row = mysql_fetch_row($result);
extract($row);

echo "<tr>";
echo "<td align = \"center\">";
echo "<a href = \"item.php?id=$pd_id\"><img src=\"$pd_path\" border=\"0\"><br>$pd_name</a>";
echo "</td>";
echo "</tr>";

 

for some reason i get the error in the title though

 

Unknown column '38' in 'where clause'

 

but when i manually enter the sql using 38 instead of id it works so im confused

all i did was copy $sql delete the begining and change id to 38 and used it in php my admin with ease.

Change

$id = $_GET['id'];
$id = mysql_real_escape_string($id);

//$sql = "SELECT * FROM tbl_product WHERE pd_id = $'id'";

$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$id'";

 

to

if(isset($_GET['id']) && !is_numeric($_GET['id']))
   die('Forbidden');

$id = (int) $_GET['id'];

$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = $id";

 

mysql_real_escape_string should only be used on strings, not numbers.

Change

<?php
$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$id'";
$result = mysql_query ($sql) or die (mysql_error());
?>

to

<?php
$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$id'";
$result = mysql_query ($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
?>

 

This will show you what your query is. Please post that, since it might give a hint.

 

Ken

 

 

Change

<?php
$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$id'";
$result = mysql_query ($sql) or die (mysql_error());
?>

to

<?php
$sql = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$id'";
$result = mysql_query ($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
?>

 

This will show you what your query is. Please post that, since it might give a hint.

 

Ken

 

This is going to sound really messed up but i entered your code i know i uploaded the right file after saving i know im looking at the right file, and i still got the same error.

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.