View Full Version : $_Session not storing on first attemp

11-25-2011, 10:53 AM
Please help me on my coding im having problem with the session which only storing the session on second on the first it just not storing any session





if(!isset($_SESSION['ddc']['cartqty'])) $_SESSION['ddc']['cartqty'] = 0;

if(!isset($_SESSION['ddc']['price'])) $_SESSION['ddc']['price'] = 0.00;




$msearch = $_GET['search'];



if ($_SESSION['sort'] == ""){
$_SESSION['sort']="ORDER BY name";

echo $_SESSION['msr']

<div class="clear"></div>

<div id="menulisting">
<div style="margin-bottom : 10px">
<a href="mobilesms.php">
<img id="mobile" src="assets/images/mobilesms.jpg" style="border: 0px none;"></a>

<?php include('includes/menu.php'); ?>
<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FDonkeez%2F147416101995311&amp;width=180&amp;colorsc heme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;height=250" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:180px; height:250px;" allowTransparency="true"></iframe>

<div id="productlisting" style="border: 0px none;">

<div id="intcategories">

<div id="categoryname"><h>Product Search</h></div>
<div id="new">New product

<div id="newproduct">
<marquee behavior="scroll" scrolldelay="100" direction="left" onmouseover="this.stop();" onmouseout="this.start();" style="height: 50px;"> <div id="newproduct1">

$sql3 = "SELECT * FROM ddcart_products ORDER BY id DESC LIMIT 0,8";
$result3 = mysql_query($sql3);
while($data3 = mysql_fetch_assoc($result3)) {
<img src="<?php echo 'productimages/'.$data3['stock'], '.jpg'; ?>">
<?php } ?></div>

<div class="clear" style="height: 1px;"></div>


<div id="newborder">
<div id="intcategories2">

<div id="subcats" style="height: 40px;"><form method="get" action="search.php">
<input type="text" style="height: 26px; width: 139px; padding-bottom: 0px; padding-top: 0px; margin-bottom: 5px; margin-top: 5px;" class="box" value="" name="search">
<input type="submit" value="Search" class="button">


<div class="clear" style="height: 1px;"></div>


<div class="clear" style="height: 1px;"></div>

11-25-2011, 12:34 PM
Is your code in different pages? It looks a mess...

I didn't really investigate but from what I can see from the above code, you can't have a session_start() in the middle of a page.

From php.net: To use cookie-based sessions, session_start() must be called before outputing anything to the browser.