PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
KevinCB
Forum Commoner
Posts: 32 Joined: Tue Mar 01, 2005 6:00 am
Post
by KevinCB » Fri May 27, 2005 5:46 am
I'm having a problem with the following script. I have a script that lists the categories in the database and then the items that are in that category, which is working fine.
But then when I select the item from the category to display it in more detail the script just displays a blank screen with no errors or anything. Here is the script:
Code: Select all
<?php
//validate item
$get_item = "select c.cat_name, si.item_name, 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.id = $_GET['item_id']";
$get_item_res = mysql_query($get_item) or die(mysql_error());
if (mysql_num_rows($get_item_res) < 1) {
//invalid item
$cat_name = strtoupper(stripslashes(mysql_result($get_item_res,0,'cat_name')));
$item_name = stripslashes(mysql_result($get_item_res,0,'item_name'));
$item_price = mysql_result($get_item_res,0,'item_price');
$item_desc = stripslashes(mysql_result($get_iem_res,0,'item_desc'));
$item_image = mysql_result($get_item_res,0,'item_image');
//make breadcrumb trail
$display_block .= "<p><strong><em>You are viewing:</em><br>
<a href=\"seestore.php?cat_id=$cat_id\">$cat_name</a>
> $item_name</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
$get_colours = "select shirt_colour from store_shirts where
item_id = $item_id order by shirt_colour";
$get_colours_res = mysql_query($get_colours) or die(mysql_error());
if (mysql_num_rows($get_colours_res) > 0) {
$display_block .= "<p><strong>Available Colours:</strong><br></p>";
while ($colours = mysql_fetch_array($get_colours_res)) {
$shirt_colour = $colours['shirt_colour'];
$display_block .= "$shirt_colour<br>";
}
}
//get sizes
$get_sizes = "select shirt_size from store_shirts where
item_id = $item_id order by shirt_size";
$get_sizes_res = mysql_query($get_sizes) or die(mysql_error());
if (mysql_num_rows($get_sizes_res) > 0) {
$display_block .= "<p><strong>Available Sizes:</strong><br></p>";
while ($sizes = mysql_fetch_array($get_sizes_res)) {
$shirt_size = $sizes['shirt_size'];
$display_block .= "$shirt_size<br>";
}
}
$display_block .= "
</td>
</tr>
</table>";
}
?>
The database field and table names are all correct, so I have no idea what is going on, could anyone help.
Thanks
Last edited by
KevinCB on Tue Jun 07, 2005 4:47 pm, edited 1 time in total.
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Fri May 27, 2005 5:47 am
this is a common outcome from an error in your script
Code: Select all
// add this to the top of your page
error_reporting(E_ALL);
It still may not show an error, but check syntax especially
KevinCB
Forum Commoner
Posts: 32 Joined: Tue Mar 01, 2005 6:00 am
Post
by KevinCB » Fri May 27, 2005 6:22 am
Didn't show an error, I have looked at the syntax in the colour coded editor I'm using and it looks ok.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri May 27, 2005 7:37 am
are you getting any rows returned?
KevinCB
Forum Commoner
Posts: 32 Joined: Tue Mar 01, 2005 6:00 am
Post
by KevinCB » Fri May 27, 2005 7:45 am
No nothing is, it's just a white blank screen no information on it whatsoever.
So nothing is being echoed onto the page.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri May 27, 2005 7:57 am
in your query
Code: Select all
$get_colours = "select shirt_colour from store_shirts where
item_id = $item_id order by shirt_colour";
Where are you getting $item_id from
I see $_GET['item_id'] on line 6 of your posted code but I never see it transformed into $item_id.
KevinCB
Forum Commoner
Posts: 32 Joined: Tue Mar 01, 2005 6:00 am
Post
by KevinCB » Fri May 27, 2005 8:10 am
The $item_id is in another script, basically this script links to the one that lists the items, but this script merely displays the item you click on from the list on a page, if that makes sense. Here's the other script anyway.
Code: Select all
<?php
//show categories first
$get_cats = "select id, cat_name, cat_desc from
store_categories order by cat_name";
$get_cats_res = mysql_query($get_cats) or die(mysql_error());
if (mysql_num_rows($get_cats_res) < 1) {
$display_block = "<p><em>Sorry, no categories to browse.</em></p>";
} else {
while ($cats = mysql_fetch_array($get_cats_res)) {
$cat_id = $cats[id];
$cat_name = strtoupper(stripslashes($cats[cat_name]));
$cat_desc = stripslashes($cats[cat_desc]);
$display_block .= "<p><strong><a
href=\"$_SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_name</a></strong>
<br>$cat_desc</br></p>";
if ($_GET[cat_id] == $cat_id) {
//get items
$get_items = "select id, item_name, item_price
from store_items where cat_id = $cat_id
order by item_name";
$get_items_res = mysql_query($get_items) or die(mysql_error());
if (mysql_num_rows($get_items_res) < 1) {
$display_block = "<p><em>Sorry, no items in this category</em></p>";
} else {
$display_block .= "<ul>";
while ($items = mysql_fetch_array($get_items_res)) {
$item_id = $items[id];
$item_name = stripslashes($items[item_name]);
$item_price = $items[item_price];
$display_block .= "<li /><a
href=\"showitems.php?item_id=$item_id\">$item_name</a>
</strong> (£$item_price)";
}
$display_block .="</ul>";
}
}
}
}
?>
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri May 27, 2005 10:46 am
fine try this
Code: Select all
$get_colours = "select shirt_colour from store_shirts where
item_id = $_GET['item_id'] order by shirt_colour";
$get_colours_res = mysql_query($get_colours) or die(mysql_error());
what do you get?
( JAM | Edited spelling error. )
KevinCB
Forum Commoner
Posts: 32 Joined: Tue Mar 01, 2005 6:00 am
Post
by KevinCB » Mon Jun 06, 2005 7:29 am
I have tried what you said,but it still comes up with a blank screen.
I applied what you said to the t-shirt sizes as well, and still don't get anything echoed out onto the screen.
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Mon Jun 06, 2005 8:55 am
Do you echo the display_block anywhere ?
If yes try placing some additional debug "echos" in.
Code: Select all
<?php
echo("e;DEBUG:start"e;);
//code
echo("e;DEBUG:check1"e;);
//code
echo("e;DEBUG:check2"e;);
....
?>
KevinCB
Forum Commoner
Posts: 32 Joined: Tue Mar 01, 2005 6:00 am
Post
by KevinCB » Tue Jun 07, 2005 4:22 pm
Thanks for that tip CoderGoblin, since I'm relatively new to PHP didn't know you could do that, I'll keep that in mind for the future.
Anyway, I did the Debug echoes, and found out I had a typo in the MySQL query.
I've now corrected this but found out that it doesn't like the following line now:
Code: Select all
$item_name = stripslashes(mysql_result($get_item_res,0,'item_name'));
And so I have now got the page showing the page heading, but nothing else so I'm completely baffled again.