Hi i want to echo session but it gives error...code is

session_start();
	if(isset($_GET['P_Price']))
	{
	$_SESSION['Price'] = $_SESSION['Price']+ $_GET['P_Price'];
	  $_SESSION['Items']++; 
	
	
	
   " <div class=\"shopping_cart\">
        	<div class=\"cart_title\">Shopping cart</div>
            
            <div class=\"cart_details\">Items 
          echo  $_SESSION['Items'];  <br />   /// this line has error
            <span class=\"border_cart\"></span>
            Total: <span class=\"price\">echo $_SESSION['Price']; </span>      ////this line has error also
            </div>
            
            <div class=\"cart_icon\"\><a href=\"#\" title=\"header=[Checkout] body=[&nbsp;] fade=[on]\"><img src=\"images/shoppingcart.png\" alt=\"\" title=\"\" width=\"48\" height=\"48\" border=\"0\" /></a></div>
        
        </div>";

maybe you should use variable, like this:

$variable=$_SESSION['Price'];
$variable+=$_GET['P_Price']; //if doesn't work, then do this:$variable=$variable*1+$_GET['P_Price'];
$variable++;
$_SESSION['Price']=$variable;

No dear its not working...just tell me how can u echo session in html code?

" <div class=\"shopping_cart\">
<div class=\"cart_title\">Shopping cart</div>

<div class=\"cart_details\">Items
echo $_SESSION; <br /> /// this line has error
<span class=\"border_cart\"></span>
Total: <span class=\"price\">echo $_SESSION; </span> ////this line has error also
</div>

<div class=\"cart_icon\"\><a href=\"#\" title=\"header=[Checkout] body=[&nbsp;] fade=[on]\"><img src=\"images/shoppingcart.png\" alt=\"\" title=\"\" width=\"48\" height=\"48\" border=\"0\" /></a></div>

</div>";

Wrong syntax. Try with below:

echo  "<div class=\"shopping_cart\">\n
        	<div class=\"cart_title\">Shopping cart</div>\n
            
            <div class=\"cart_details\">Items " . $_SESSION['Items'] . "<br /><span class=\"border_cart\"></span>
            Total: <span class=\"price\">" . $_SESSION['Price'] . "</span>\n
            </div>\n            
            <div class=\"cart_icon\"\><a href=\"#\" title=\"header=[Checkout] body=[&nbsp;] fade=[on]\"><img src=\"images/shoppingcart.png\" alt=\"\" title=\"\" width=\"48\" height=\"48\" border=\"0\" /></a></div>\n
        </div>\n";

'\n' for line feed. It will force to appear HTML tag from the new line in the source code.

Can you tell us the exact error you are getting???
The error that you have is because you are using php script inside the html....
Zero13 has explained the way to write it in proper format..

if you want to echo any php variable inside a string you should use this way of writing

'{$variable}' and nothing else because the other might be good a echo or print but you will face problems in sql
aw it's like

$trick = $_SESSION['whateveryouwant'];

print("this is a session test '{$trick}'");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.