Foser Posted May 21, 2007 Share Posted May 21, 2007 <?php start_session(); if (isset($_SESSION['views'])); { $_SESSION['views'] = $_SESSION['views'] + 1; } elseif (isset($_SESSION['views']) == 10); { unset($_SESSION['views']); } else $_SESSION['views'] = 1; ?> I don't understand what is the problem with my elseif command. Looks good to me, I've played arround with it a bit but does not work! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/ Share on other sites More sharing options...
jitesh Posted May 21, 2007 Share Posted May 21, 2007 <?php session_start(); if (isset($_SESSION['views']) and $_SESSION['views'] < 10) { $_SESSION['views'] = $_SESSION['views'] + 1; } elseif (isset($_SESSION['views']) == 10) { unset($_SESSION['views']); } else { $_SESSION['views'] = 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258111 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 <?php start_session(); if (isset($_SESSION['views'])) { $_SESSION['views'] = $_SESSION['views'] + 1; }elseif (isset($_SESSION['views']) == 10){ unset($_SESSION['views']); $_SESSION['views'] = 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258112 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 and $_SESSION['views'] < 10 i dont understand why we need this? <?php start_session(); if (isset($_SESSION['views'])) { $_SESSION['views'] = $_SESSION['views'] + 1; }elseif (isset($_SESSION['views']) == 10){ unset($_SESSION['views']); $_SESSION['views'] = 1; } ?> and i dont see a difference... Ive played with those {} and it does not work. Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258172 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 try this counts to 10 then back to 1 <?php session_start(); //<-- corrected if ($_SESSION['views'] == 10) { unset($_SESSION['views']); } if (isset($_SESSION['views'])) { $_SESSION['views'] = $_SESSION['views'] + 1; }else{ $_SESSION['views'] = 1; } echo "Views:".$_SESSION['views']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258174 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 <?php session_start(); if (isset($_SESSION['views'])); { $_SESSION['views'] = $_SESSION['views'] + 1; } if (isset($_SESSION['views']) == 10); { unset($_SESSION['views']); } else { $_SESSION['views'] = 1; } ?> well ive fixed a few twicks but in a different order than yours why does it matter that unset is before isset i get a unwanted else command apparenthly :S thanks, just trying to understand php and thanks for the great help so far!~ Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258241 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 i used unset first to make the isset fail thus setting it back to 1 hope that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258246 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 thanks, last question then im pressing solve When the script will unset what will it show as an echo on the browser? Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258256 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 nothing try this echo $var; as $var isn't set thiers nothing to echo, same when you unset.. it no longer exists (so isset will be false) but $var=""; will echo nothing but isset will be true as it exists but contains an empty string.. make sense ? Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258265 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 yea, i got it working now. but for some reason the season variable isn't going up after a refresh. <?php session_start(); if ($_SESSION['view'] == 10); { unset($_SESSION['view']); } if (isset($_SESSION['view'])) $_SESSION['view'] = $_SESSION['view']+ 1; else { $_SESSION['view'] = 1; } echo "Views: " .$_SESSION['view']. "<br> This will reset after 10 refreshes."; ?> I checked my very basic season counter and looks like this, can't find the mistake. Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258284 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 <?php session_start(); if ($_SESSION['view'] == 10); { unset($_SESSION['view']); } if ( isset($_SESSION['view']) ) //somthing is missing here { //Ahh thats better $_SESSION['view']++; //add's 1 else { $_SESSION['view'] = 1; } echo "Views: " .$_SESSION['view']. "<br> This will reset after 10 refreshes."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258294 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 <?php session_start(); if ($_SESSION['view'] == 10); { unset($_SESSION['view']); } if (isset($_SESSION['view'])) { $_SESSION['view'] = $_SESSION['view']++; } else { $_SESSION['view'] = 1; } echo "Views: " .$_SESSION['view']. "<br> This will reset after 10 refreshes."; ?> It still does not add for some reason :S Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258301 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 Oh LOL yeah ; ends a statement see IF you can find the problem try 10 attempts i think thats too many hints Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258302 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 if (isset($_SESSION['view'])); { when i do this i get Parse error: syntax error, unexpected T_ELSE in C:\WAMP\www\Tutorials\Simple_PHP\SESSIONS\unset_Function\index.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258310 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 wrong one If starts a block ie <?php if( $a == $b) { echo "hello "; echo "world" } ?> Quote this post to see the how to fix (or try to find it, as your intrested in learning bug finding is key) if ($_SESSION['view'] == 10); { to if ($_SESSION['view'] == 10) { Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258312 Share on other sites More sharing options...
Foser Posted May 21, 2007 Author Share Posted May 21, 2007 Great works fine! Thanks a lot for your patience I've learned a lot Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258315 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 cool i know that was probably a pain but it helps laters :-\ don't hate me Quote Link to comment https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/#findComment-258316 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.