Given a php form that submits to it’self,
via <?php echo $_SERVER[‘PHP_SELF’];?>
And the same form with some html and one submit button
<label for="submit">Submit</label>
<input id="submit" type="submit" value="Submit Info:" /><br />
How do I set it up, such that when the user has finished inputting all the relevant
information on the form(one, form.php), without any errors, the session is destroyed, after pressing
the submit button.
I know this starts a session:
<?php session_start() ?>
At the top of form.
And this destroys the session variables
session_destroy();
Would I have to do something like this:
$_SESSION[‘submit’] = ‘submit’;
I am trying to avoid creating sessions for each variable on my form, for
example,
name
age
sex
It sounds like it would be a lot of work to create sessions for each and every
variable on a given form, that’s why I am here seeking answers, in the meantime
I will read more on sessions, thank you for not flaming the newb.
Why exactly are you using sessions? If it is for formprocessing you should use POST or alternativly GET. SESSIONS are a great way to store configurations, accesslevel settings, shoppingcarts etc.
BTW, if you are going to use sessions, you can also just create one session and store all sessiondata in an array, then submit that array to a
$_SESSION["mySession"].E.g. if you have a maximum amount of weblogs to show on a page this could be retrieved like
$_SESSION["mySession"]["maximum_amount_of_weblogs_per_page"].Then ofcourse you have to add the
array("maximum_amount_of_weblogs_per_page" => 10);to$_SESSION["mySession"].Hope it’s useful to you.