i am trying to set session variable using a form but i ahve never done this before and i am unsure of how this is done. i have had a look at a few examples on line but still i am not clear on how this works.

here is what i have up to now to register the variables

<?php
session_start();
$_SESSION["dropdown"];
$_SESSION["radio"];
$_SESSION["dropdown2"];
$_SESSION["radio2"];
?>

i have a form on the page which has different form elements which are named dropdown, radio etc. if i want it to record what choices the user has made on the form will this work.

if i want to use these on the next page would i write something like this

<?php
session_start();
$_SESSION["dropdown"] = $db;
$_SESSION["radio"] = $table;
$_SESSION["dropdown2"] = $db2;
$_SESSION["radio2"] = $table2;
?>

would $db be set to the value taken from the form?

i have tried to do this using the post method bit i am not getting the correct values sent through to the next page. here is the code for the data which i sent to the first page in question

$id = $_POST['id'];
$db = $_POST['dropdown2'];
$table = $_POST['radio2'];

then i have a form at the bottom which is populated using a mysql query. this page is used for editing data entered into a mysql db. here is the code for the form

$sql = ("SELECT * FROM $table WHERE id = $id");
$result = mysql_query($sql);

$row = mysql_fetch_array($result) or die(mysql_error());
echo "<form action=\"update.php\" method=\"post\">";
echo "Date:&nbsp;<input type=\"text\" name=\"date\" value=\"{$row['date']}\" /><br /><br>";
echo "Title:&nbsp;&nbsp;<input type=\"text\" name=\"title\" value=\"{$row['title']}\" /><br /><br />";
echo "<input type=\"hidden\" name=\"dropdown\" value=\"{$db['dropdown2']}\" /><br /><br />";
echo "<input type=\"hidden\" name=\"radio\" value=\"{$table['radio2']}\" /><br /><br />";
echo "<input type=\"hidden\" name=\"id\" value=\"{$id['id']}\" /><br /><br />";
echo "Article:<br /><textarea cols=\"50\" rows=\"10\" name=\"article\" onkeyup=\"textLimit(this, 500)\">{$row['article']}</textarea><br />";
echo "<input type=\"submit\" />";
echo "</form>";

that bit works fine but when i go to the update page which has this code at the top

$db = $_POST['dropdown'];
$table = $_POST['radio'];

$id = $_POST['id'];

$a = $_POST['date'];
$b = $_POST['title'];
$c = $_POST['article'];

i can echo out values for all the variable except $db and $table i get values for them which are c and i.

any help with this would be great

sorted. the proble was with the hidden form data i was trying to pass the data on for them wrong. here is wat was wrong

echo "<input type=\"hidden\" name=\"dropdown\" value=\"{$db['dropdown2']}\" /><br /><br />";
echo "<input type=\"hidden\" name=\"radio\" value=\"{$table['radio2']}\" /><br /><br />";
echo "<input type=\"hidden\" name=\"id\" value=\"{$id['id']}\" /><br /><br />";

here is what i changed it to to get it to work

echo "<input type=\"hidden\" name=\"dropdown2\" value=\"$db\" /><br /><br />";
echo "<input type=\"hidden\" name=\"radio2\" value=\"$table\" /><br /><br />";
echo "<input type=\"hidden\" name=\"id\" value=\"{$id['id']}\" /><br /><br />";

you may notice that i did not change the id section. this did not change as it was being sent to the next page with no problems. the only reason i can think that it was having difficulty with the other two sections was that they where passed to the first page using hidden form data. if anyone can explain this problem to me them please do as i have fixed the problem but do not understand why it was being caused in the first place.

This article has been dead for over six months. Start a new discussion instead.