0

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>";

Edited by Farhad.idrees: n/a

5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by mamdouh ramadan
0

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;

Edited by ivan3510: n/a

2

" <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.

0

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..

Edited by IIM: n/a

0

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}'");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.