Page 1 of 1

Problems running a session

Posted: Fri Jun 10, 2005 4:53 am
by KevinCB
I'm having problems on a script that runs a session. I have narrowed it down and think the problem is with running this session, as all I get is a blank screen when running it. I have debugged the script and found that when I comment out parts of the code and the session_start(); then it dispays part of it, whereas when I leave session_start(); in it just displays 'DEBUG:start' on the page. Here is the code with the parts commented out.

Code: Select all

<?php
error_reporting(E_ALL);
//echo ("DEBUG:start");
//session_start();

echo ("DEBUG:check1");
$display_block .= "<h1>Shoot The Moon Records - Item Detail</h1>";

echo ("DEBUG:check2");
//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]";

echo ("DEBUG:check3");
$get_item_res = mysql_query($get_item)  or die(mysql_error());

echo ("DEBUG:check4");
if (mysql_num_rows($get_item_res) < 1) {
   //invalid item
   $display_block .= "<p><em>Invalid item selection.</em></p>";
} else {
echo ("DEBUG:check5");
   $cat_name = strtoupper(stripslashes(mysql_result($get_item_res,0,'cat_name')));
echo ("DEBUG:check6");
   $item_name = stripslashes(mysql_result($get_item_res,0,'item_name'));
echo ("DEBUG:check7");
   $item_price = mysql_result($get_item_res,0,'item_price');
echo ("DEBUG:check8");
   $item_desc = stripslashes(mysql_result($get_iem_res,0,'item_desc'));
echo ("DEBUG:check9");
   $item_image = mysql_result($get_item_res,0,'item_image');

echo ("DEBUG:check10");
   //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>";
echo ("DEBUG:check11");
//	 <form method=\"post\" action=\"addtocart.php\">";

//echo ("DEBUG:check12");
   //get colours
//   $get_colours = "SELECT shirt_colour FROM store_shirts WHERE
//	  item_id = $_GET[item_id] ORDER BY shirt_colour";
//echo ("DEBUG:check13");
//   $get_colours_res = mysql_query($get_colours)  or die(mysql_error());

echo ("DEBUG:check14");
   if (mysql_num_rows($get_colours_res) > 0) {

//       $display_block .= "<p><strong>Available Colours:</strong></p>
//			 <select name=\"sel_shirt_colour\">";

echo ("DEBUG:check15");
       while ($colours = mysql_fetch_array($get_colours_res)) {
	   			$shirt_colour = $colours['shirt_colour'];
//     			$display_block .= "
//		  		<option value=\"$shirt_colour\">$shirt_colour</option>";
       }
       
//       $display_block .= "</select>";
   }

//echo ("DEBUG:check16");
    //get sizes
//    $get_sizes = "SELECT shirt_size FROM store_shirts WHERE
//		 item_id = $_GET[item_id] ORDER BY shirt_size";
//echo ("DEBUG:check17");
//    $get_sizes_res = mysql_query($get_sizes)  or die(mysql_error());

echo ("DEBUG:check18");
    if (mysql_num_rows($get_sizes_res) > 0) {

//	$display_block .= "<p><strong>Available Sizes:</strong></p>
//	<select name=\"sel_shirt_size\">";

echo ("DEBUG:check19");
	while ($sizes = mysql_fetch_array($get_sizes_res)) {
	    $shirt_size = $sizes['shirt_size'];
//      $display_block .= "
//			 <option value=\"$shirt_size\">$shirt_size</option>";
	     }
	
//	     $display_block .= "</select>";
   }

//echo ("DEBUG:check20");
//     $display_block .= "
//     <p><strong>Select Quantity:</strong></p>
//     <select name=\"sel_item_qty\">";

echo ("DEBUG:check21");
     for ($i=1; $i<11; $i++) {
//					$display_block .= "<option value =\"$i\">$i</option>";
		 }

//echo ("DEBUG:check22");
//		 $display_block .= "
//		 </select>
//		 <input type=\"hidden\" name=\"sel_item_id\" value=\"$_GET[item_id]\">
//		 <p><input type=\"submit\" name=\"submit\" value=\"Add to Cart\"></p>
//		 </form>
//     </td>
//     </tr>
//     </table>";

}
?>

Posted: Fri Jun 10, 2005 5:01 am
by Syranide
That surely sounds very strange, unless there is some hidden error that takes effect. (and that session_start would buffer the content and not send it)

All I can say is, create a new file, the same way you did now, but only use session_start and an echo on both sides... if that doesn't work the not even god can help you I guess.

however, if it is works, I'm guessing there is some hidden error, or that session_start bails for some reason.
(note that error_reporting all doesn't always work as one would expect)

but it's great that you have learnt how to really debug it yourself before asking here. :idea: