954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Session echo

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'];     /// 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>";
Farhad.idrees
Junior Poster in Training
63 posts since Dec 2010
Reputation Points: 11
Solved Threads: 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;
ivan3510
Junior Poster
156 posts since Aug 2010
Reputation Points: 13
Solved Threads: 4
 

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

Farhad.idrees
Junior Poster in Training
63 posts since Dec 2010
Reputation Points: 11
Solved Threads: 0
 
" Shopping cart Items echo $_SESSION['Items'];
/// this line has error Total: echo $_SESSION['Price']; ////this line has error also \"\" ";


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

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

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

IIM
Junior Poster
165 posts since Jun 2011
Reputation Points: 46
Solved Threads: 37
 

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}'");
mamdouh ramadan
Newbie Poster
11 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: