in reply to Submit button increment value

I went ahead and fixed your code formatting. The proper way to format code is to place a <code> tag on the line before your code, then paste all your code (with proper 0x20-based indentation), then place a </code> tag on the line following all of your code. What you shouldn't be doing is placing <br/><code> line of code </code> for each line of your code. Formatting is lost, mistakes are made, and it becomes a lot of work to fix.

Now for your "problem". You're setting $var = 0 each time the script is run. But you're not reading the session back in and using it to set $var to the value previously set in the session before incrementing it again. That means that when a user hits submit, you increment $var from 0 to 1, and you save it to the session, but you don't retrieve it prior to incrementing, so subsequent runs will always start at zero again.

CGI is stateless, and you must be aware of that or you wouldn't be using the CGI::Session module. But it really is stateless: You have to expect that when submit is clicked, the script is re-run from the start as though it never ran before. To maintain state, you need to be retrieving the appropriate session and setting $var to the previous state before incrementing it.

Also, you shouldn't over-complicate your code by adding else{} clauses to all of your if statements, unless there's something for the else{} clause to do. There may be times when adding them increases readability, but as it stands, they detract from it, IMO.


Dave