Merry Christmas all.
I have a question about isset and methods.
I want some variables to be written to a session variable when a button is clicked. I can set variables to the session variable just fine, but problems occur once I use set methods inside the if statement for 'isset'.
I imagine this is because the whole script executes, and adds all the data to the session variables, then when the button is clicked the session variables have already been defined and so the new data does not get added, is that right?

<?php
	if (isset($_POST['submit'])) {
// this does not work
			$_SESSION['myTest']->setAnswer("set inside if");

   }
// this does work
$_SESSION['myTest']->setAnswer("set outside if");
?> 

Cross post here

    I'd imagine that it's actually the if declaration screwing up the whole kit-and-kaboodle. Do a print_r on your $_POST array, and see if submit is in there. Make sure the it's submit and not Submit, case does make a difference in array elements.

      print_r on $_POST('submit') gives this error syntax error, unexpected T_VARIABLE.
      Although I have worked out that the set methods within the for loop arenot being executed, if I take them out then the if works, if the set methods are there then it does not work.

        hmm... why did you do a print_r() on $POST('submit') when you want to use it on $POST['submit']?

          Sorry typo on my part.
          It'll let me do print, but not print_r.
          print just prints "submit".
          And I changed all the values to submit, rather than Submit to avoid typos.

            Write a Reply...