Question:

What is wrong in this code +PHP?

by  |  earlier

0 LIKES UnLike

hi I get these two error message

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/html/test.php:7) in /home/html/test.php on line 9

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/public/test.php:7) in /home/public/test.php on line 9

No Product In the Basket

<?php

session_start();

if(!empty($_REQUEST['quantity']))

{

if(!isset($_SESSION['products']))

{

echo"<p>add new session</p>";

echo"got".$_REQUEST['quantity']."gg<...

$_SESSION['products'][0]=$_REQUEST['...

echo "add".$_SESSION['products'][0]."to session";

}

else

{

echo "add new product to the list";

echo"got".$_REQUEST['quantity']."gg<b...

$_SESSION['products'][sizeof($_SESSI...

}

}

else

{

echo "No Product In the Basket " ;

}

?>

 Tags:

   Report

2 ANSWERS


  1. &lt;?php

    @session_start();

    if(!empty($_REQUEST[&#039;quantity&#039;]))

    {

    if(!isset($_SESSION[&#039;products&#039;]))

    {

    echo&quot;&lt;p&gt;add new session&lt;/p&gt;&quot;;

    echo&quot;got&quot;.$_REQUEST[&#039;quantity&#039;].&quot;gg&lt;.....

    $_SESSION[&#039;products&#039;][0]=$_REQUEST[&#039;.....

    echo &quot;add&quot;.$_SESSION[&#039;products&#039;][0].&quot;to session&quot;;

    }

    else

    {

    echo &quot;add new product to the list&quot;;

    echo&quot;got&quot;.$_REQUEST[&#039;quantity&#039;].&quot;gg&lt;b....

    $_SESSION[&#039;products&#039;][sizeof($_SESSI.....

    }

    }

    else

    {

    echo &quot;No Product In the Basket &quot; ;

    }

    ?&gt;

    session_start() this will be added on top of page if u dont then use @session_start();


  2. The error messages mean that you have called session_start() after the &lt;HEAD&gt;&lt;/HEAD&gt; element of the HTML page. You cannot do this because &lt;/HEAD&gt; causes the headersto be sent to the output buffer, and session_start() needs to be able to write header information. You need to move the code.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.