Page 1 of 1

Incrementing a Variable

Posted: Mon Mar 06, 2006 9:41 am
by ferio-moreno
hello, basic help needed, I was trying to make a code, that upon refresh, it would increment a variable by +1 each time. But it doesn't seem to quite work, i dont want to use any sessions or cookies with this.

Here's my code. any pointers?

Code: Select all

<?php
	$inc = 0;
	if ($inc != "20"){
		$inc = $inc + 1;
	}else{
		$inc = 0;
	}
?>
<input type="hidden" name="increment" value="<?php echo $inc; ?>" />

Posted: Mon Mar 06, 2006 9:46 am
by feyd
remove the first $inc = 0 occurance.

Posted: Mon Mar 06, 2006 9:56 am
by ferio-moreno
i get this
Notice: Undefined variable: inc in c:\Inetpub\wwwroot\demoform\calendar\demo_week.php on line 20

Posted: Mon Mar 06, 2006 10:12 am
by feyd

Posted: Mon Mar 06, 2006 10:24 am
by ferio-moreno
im just confusing myself right now (i'm an extreme novice in php).

ive used issets before but i dont know when and when not to use them in the code that i posted above....

Posted: Mon Mar 06, 2006 10:30 am
by feyd

Code: Select all

if(isset($inc) and $inc <= 20)