NickG21 Posted December 29, 2006 Share Posted December 29, 2006 this is my first time using sessions and i think that i am pretty close to having this right. i am unable to reset my CurrencyID when the image is clicked on in my form. does anyone know where i am going wrong with this?[code]<?php$CurrencySymbols = array( 1 => "\$", 2 => "€", 3 => "£");//Examples Made Up$CurrencyExchangeRate = array(1 => 1, 2 => 0.759594, 3 => 0.510553);$_SESSION["CurrencyID"] = isset($_SESSION["CurrencyID"]) ? $_SESSION["CurrencyID"] : 1;$ItemPrice = 80;$CurrencyPrice = $ItemPrice * $CurrencyExchangeRate[$_SESSION["CurrencyID"]];echo $CurrencySymbols[$_SESSION["CurrencyID"]].$CurrencyPrice;if(isset($_GET["currencyID"])){if(is_numeric($_GET["currencyID"])){$_SESSION["CurrencyID"] = $_GET["currencyID"];}}?><html><body><form action="converter.php" method="GET"><a href="converter.php?currencyID=1"><img src="./usd.jpg" align="left" border="0"></a><a href="converter.php?currencyID=2"><img src="./euro.jpg" align="left" border="0"></a><a href='".$_SERVER['PHP_SELF']."?currencyID=3'>British Sterling</a><br /></form></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/ Share on other sites More sharing options...
genericnumber1 Posted December 29, 2006 Share Posted December 29, 2006 session_start()? Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/#findComment-149340 Share on other sites More sharing options...
NickG21 Posted December 29, 2006 Author Share Posted December 29, 2006 yea, i realized that a little late but it still doesn't work lolthanks though, another amateur mistake for me to add to the list Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/#findComment-149341 Share on other sites More sharing options...
dbo Posted December 29, 2006 Share Posted December 29, 2006 Check out my post on this thread:http://www.phpfreaks.com/forums/index.php/topic,120155.0.htmlIt might help answer your question, might not... Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/#findComment-149353 Share on other sites More sharing options...
genericnumber1 Posted December 29, 2006 Share Posted December 29, 2006 You don't really need those form HTML tags... though they might just be hanging around from your real code... also I'd like to remind you that since you are setting the $_SESSION['CurrencyID'] AFTER the logic... it won't be set until the script is run again...if it's converter.php?currencyID=2 it will still display USD for one run (will be euro if you refreshed the page) since you don't change the value of $_SESSION['CurrencyID'] until after you do your..."echo $CurrencySymbols[$_SESSION["CurrencyID"]].$CurrencyPrice;" Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/#findComment-149367 Share on other sites More sharing options...
wildteen88 Posted December 29, 2006 Share Posted December 29, 2006 try that:[code]<?phpsession_start();if(!isset($_GET["currencyID"])){ $_SESSION["CurrencyID"] = isset($_SESSION["CurrencyID"]) ? $_SESSION["CurrencyID"] : 1;}elseif(isset($_GET["currencyID"])){ if(is_numeric($_GET["currencyID"])) { $_SESSION["CurrencyID"] = $_GET["currencyID"]; }}$CurrencySymbols = array( 1 => "\$", 2 => "€", 3 => "£" );//Examples Made Up$CurrencyExchangeRate = array( 1 => 1, 2 => 0.759594, 3 => 0.510553 );$ItemPrice = 80;$CurrencyPrice = $ItemPrice * $CurrencyExchangeRate[$_SESSION["CurrencyID"]];echo $CurrencySymbols[$_SESSION["CurrencyID"]].$CurrencyPrice;?><html><body><a href="?currencyID=1"><img src="./usd.jpg" align="left" border="0" alt="USD" /></a><br /><a href="?currencyID=2"><img src="./euro.jpg" align="left" border="0" alt="Euro" /></a><br /><a href="<?php echo $_SERVER['PHP_SELF']; ?>?currencyID=3">British Sterling</a><br /></body></html>[/code]You had some of your code in the wrong place. Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/#findComment-149374 Share on other sites More sharing options...
NickG21 Posted December 29, 2006 Author Share Posted December 29, 2006 that works perfect, thank you guys so much i don't know what i would do without the gurus and super gurus of this site Quote Link to comment https://forums.phpfreaks.com/topic/32174-solved-session-syntax/#findComment-149388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.