473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error in SELECT statement using vars from $_GET array

can some one please help me i am getting this error but i cant seem to figure out wat is wrong on line 3 everything looks fine

[PHP]<?php
$conn = mysql_connect("localhost","root","")
or die (mysql_error());
mysql_select_db("Shop_Test",$conn) or die (mysql_error());

$display_block = "<h1> My Store </h1>";

$get_item = "SELECT c.id as Cat_ID, c.cat_title, SI.Item_title,
SI.Item_Price, SI.item_desc, SI.item_Image FROM Store_Items AS SI LEFT JOIN
Store_Categories AS c on c.id =SI.Cat_ID WHERE SI.Store_ID = $_GET[Item_ID]";

$get_item_results = mysql_query ($get_item) or die (mysql_error());

if (mysql_num_rows($get_item_results)<1) {
$display_block .= "<p><em>Invalid item selection.</em></p>";
} else {
$cat_id = mysql_result ($get_item_results,0,'Cat_ID');
$cat_title = strtoupper (stripslashes (
mysql_result ($get_item_results,0, 'cat_title')));
$item_title = stripslashes (mysql_result ($get_item_results,0,'Item_title'));
$item_price = mysql_result ($get_item_results,0,'Item_Price');
$item_desc = stripslashes(mysql_result ($get_item_results,0, 'item_Desc'));
$item_image = mysql_result ($get_item_results,0,'item_Image');

$display_block .= "<p><strong><em> Youre Viewing:</em><br><a href=\"catalogue.php?Cat_ID=$Cat_ID\">$cat_title</a>
&gt; $item_title </strong></p>

<table cellpadding=3 cellspacing=3>
<tr>
<td valign=middle align=center><img src=\"$item_image\"><td>
<td valign=middle><p><strong>Description:</strong><br>$item_desc</p>
<p><strong>Price:</strong> \$$item_price</p>";

$get_colours = "SELECT Item_Colour FROM Store_Item_Colour WHERE
Store_ID = $item_id ORDER BY Item_Colour";
$get_colour_results = mysql_result ($get_colours) or die (mysql_error());

if (mysql_num_rows($get_colour_results)>0) {
$display_block .= "<p><strong>Available Colours:</strong><br>";

while ($colours = mysql_fetch_array($get_colour_results)) {
$item_colour = $colours['Item_Colour'];
$display_block .= "item_colour<br>";
}
}

$get_sizes = "SELECT Item_size FROM store_item_size WHERE
Store_ID = $item_id ORDER BY Item_size";
$get_size_results = mysql_query($get_sizes) or die (mysql_error());

if (mysql_num_rows ($get_size_results)>0) {
$display_block .= "<p><strong>Available Sizes:</strong></br>";

while ($sizes = mysql_fetch_array ($get_size_results)) {
$item_size = $sizes ['Item_size'];
$diplay_block .= "$item_size<br>";
}
}

$display_block .= "
</td>
</tr>
</table>";
}
?>[/PHP]

Please help i have to do a project thanks in advance
Feb 26 '08 #1
6 2018
nathj
938 Expert 512MB
Hi,

I've had a look over the code and I assume the first SQL is the one with the problem. Is that the case? If so then the following may be of help, if not then it's probably no good to you.

You have:
[php]
$get_item = "SELECT c.id as Cat_ID, c.cat_title, SI.Item_title,
SI.Item_Price, SI.item_desc, SI.item_Image FROM Store_Items AS SI LEFT JOIN
Store_Categories AS c on c.id =SI.Cat_ID WHERE SI.Store_ID = $_GET[Item_ID]";
[/php]

I have never managed to make the use of the $_GET array work directly in a SQL statement like that. So I would try:
[php]
$lnItemID = $_GET['Item_ID'] ;
$get_item = "SELECT c.id as Cat_ID, c.cat_title, SI.Item_title,
SI.Item_Price, SI.item_desc, SI.item_Image FROM Store_Items SI LEFT OUTER JOIN
Store_Categories c on c.id = SI.Cat_ID WHERE SI.Store_ID = $lnItemID";
[/php]
The other changes are just personal preferences but whenever I use that syntax it works first time.

The other potential issue I spotted was that you are not passing a link identifier (defined at the top of your code as $conn) to the mysql_query - this needs to be the second parameter.

I hope this helps you out.
nathj
Feb 26 '08 #2
ronverdonk
4,258 Expert 4TB
The other potential issue I spotted was that you are not passing a link identifier (defined at the top of your code as $conn) to the mysql_query - this needs to be the second parameter.
No entirely true. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. See php documentation.

Ronald
Feb 26 '08 #3
Thanks Nathj for ur reply but i had no luck with the new code still coming up with the same error. any other suggestions everything seems fine ive been sifting through the code up and down but cant seem to find the error.

please help i need to complete this for my project.
Feb 26 '08 #4
ronverdonk
4,258 Expert 4TB
The following gets rid of the MySQL error in line 3:
Expand|Select|Wrap|Line Numbers
  1. $get_item = "SELECT c.id as Cat_ID, c.cat_title, SI.Item_title, SI.Item_Price, SI.item_desc, SI.item_Image 
  2. FROM Store_Items AS SI 
  3. LEFT JOIN Store_Categories AS c on c.id =SI.Cat_ID 
  4. WHERE SI.Store_ID = '{$_GET['Item_ID']}'";
Ronald
Feb 26 '08 #5
Thanks once again ronald. uve been a great help
Feb 26 '08 #6
ronverdonk
4,258 Expert 4TB
You are welcome, until next time.

Ronald
Feb 26 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: dracolytch | last post by:
Good day all, Ok, I have a pretty tricky problem that I need some help with. I pass around search query information a fair amount (specifically WHERE statements). Normally, I just rawurlencode()...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
4
by: Gary | last post by:
Hi, I get this error " " when my web page run, what does it mean? Hope someone can help!!! Gary
3
by: caveman | last post by:
Hi i am using PHP to upload picture files to a file in my server, but for some reason it will not create thumbnails of the upload, all that happens is that where the thumbnail is meant to be...
9
by: valeberry | last post by:
index <?php include ("conn.php"); require_once("tabs.php"); ?> <html> <head> <?php tabs_header(); ?> </head> <body>
1
by: bimeldip | last post by:
Hi, I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: bimeldip | last post by:
Hi, I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
1
by: RYKLOU | last post by:
I am kinda new to php, but i do know what i am doing kinda, but i came across this error when i am trying to upload a file to my website. Fatal error: Allowed memory size of 8388608 bytes...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.