Jump to content

Small increment logical problem


Samuz

Recommended Posts

Hi guys, i'm trying to increment a variable / session value whenever 'submit' comes in the POST.

 

I can't seem to get around the logic of this.

 

Code looks like this:

 

$var = 0
if($_POST('submit'){
$_SESSION['var2'] = $var++;
}

 

What I want it to do is increment the value of the session index everytime a user clicks 'submit'.

 

But because i've reset $var to 0 everytime, it's always just going to stay at 1.

 

I just can't think of a way to achieve this, does anyone have any clue on how I can?

Link to comment
https://forums.phpfreaks.com/topic/251546-small-increment-logical-problem/
Share on other sites

why are you using $var ?? you said "What I want it to do is increment the value of the session index everytime a user clicks 'submit'."...

If you're storing this in a SESSION, each user will have his own value... (each user has his own session).

If your goal is to have a global count of how many times the form was submitted, you need to store it somewhere else (database of .txt file or whatever)... it's basically the same as a page counter, but only activated on form submission...

why are you using $var ?? you said "What I want it to do is increment the value of the session index everytime a user clicks 'submit'."...

If you're storing this in a SESSION, each user will have his own value... (each user has his own session).

If your goal is to have a global count of how many times the form was submitted, you need to store it somewhere else (database of .txt file or whatever)... it's basically the same as a page counter, but only activated on form submission...

Because the counter has to start from somewhere (0 in this example).

 

I was thinking about just going ahead and incrementing it with it without defining the starting point, but i'm not sure that will work because i'm sure PHP will return an undefined variable error. right?

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.