Jump to content

[SOLVED] unexpected elseif


Foser

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/52316-solved-unexpected-elseif/
Share on other sites

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.

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'];
?>

<?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!~

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 ?

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.


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

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

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) {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.