Incrementing a Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Incrementing a Variable

Post 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; ?>" />
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remove the first $inc = 0 occurance.
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Post by ferio-moreno »

i get this
Notice: Undefined variable: inc in c:\Inetpub\wwwroot\demoform\calendar\demo_week.php on line 20
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Post 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....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

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