I know there are tons of session tutorials on the web. I've seen them all. See one and you've basically seen them all, since they're pretty much the same tutorial with only the names changed.
They assume that you're only going to use a session for a login feature and that's it. Well, I could use a dozen or more sessions at one time. I have many different forms on a single website.
I use a generic session for a user login. But I could use a different session for this form and another session for that form, and so on and so on. Each form is for a different thing and I don't want the information from one form to get mixed up with another.
What I need is the ability to create a session called "Form 1" and somehow be able take the inputs from "Form 1" and I guess on upon hitting the "Submit" button the user inputs from the form sets a session variable. Maybe like this:
- session_start();
-
session_name(Form 1);
-
$_SESSION['first_name'] = $first_name; // from a text input
-
$_SESSION['dog_name'] = $dog_name; // from a text input
-
$_SESSION['message'] = $message; // from a textarea
I don't know if the above is correct or not.
How would you take the information one enters in a form and turn them into a session variable?
If there is a form on the "form_1.php" page, and the action is set to go to the "form_1_results.php" page, where would you put what in order to set the session variables so that if the user encountered an error and had to hit the back button to return to the "form_1.php" page the user would not have to re-enter in all of their information again?
And then when they hit Submit again, and this time everything checks out OK the information is entered into the database? AND upon a successful database entry, i.e.,
- $query = "INSERT INTO dogs VALUE ('$first_name', '$dog_name', '$message');
-
$result = mysql_query($query);
-
if (mysql_affected_rows() == 1)
-
{
-
echo "Information Entered!";
-
unset($_SESSION['first_name']);
-
unset($_SESSION['dog_name']);
-
unset($_SESSION['message']);
-
session_destroy('Form 1');
-
-
// unset and destroy this session so they can fill out another form and information won't get mixed up.
-
-
} else {
-
-
echo "There was a problem. Hit your "Back" button and fix it.";
-
}
Is this possible, and if so what would be the proper way of implementing such a thing?