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

Link to comment
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...

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.