Forum Moderators: coopster

Message Too Old, No Replies

Disappearing data $_Session or $_Post

         

Shaman13

4:21 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



I would really appreciate someone telling me what I am doing wrong here! I have two forms, the first of which checks for pre-existing names in my MySQL database and then if no pre-existing record is found sends the name "CFNAME" and "CLNAME" to a second form to add a new record to the database. The problem I think lies with my $_SESSION and $_POST variables. The two variables listed above appear in the second form initially but when I click Save disappear! If I click Save again they reappear! This could be somewhat troubling for the user trying to enter a new record! After they save the name disappears! I believe the relevant code is below. I have been pulling my hair out on this for several days! And I am already bald! Any and all suggestions are really appreciated!

Declarations on the originating form
_______________________________________
// Get the user's input from the form
$CFNAME = $_SESSION['CFNAME'];
$CLNAME = $_SESSION['CLNAME'];


// Register session key with the value


$_SESSION['LNADV'] = $LNADV;
$_SESSION['FNADV'] = $FNADV;
_______________________________________
The fields and declarations on the receiving form
_____________________________________________
<INPUT name="CFNAME" type="text" value="<? echo $_SESSION['CFNAME'];?>" size="17"></td>
<td width="200" height="25" colspan="5"><input name="CLNAME" type="text" value="<? echo $_SESSION['CLNAME'];?>" size="17"></td>

// Get the user's input from the form
$CFNAME = $_POST['CFNAME'];
$CLNAME = $_POST['CLNAME'];
$CHILDREN = $_SESSION['CHILDREN'];
$ADULTS = $_SESSION['ADULTS'];

$CASENUM= (isset($_POST['CASENUM']))? $_POST['CASENUM'] : '';

// Register session key with the value
$_SESSION['CFNAME'] = $CFNAME;
$_SESSION['CLNAME'] = $CLNAME;
$_SESSION['CHILDREN'] = $CHILDREN;
$_SESSION['ADULTS'] = $ADULTS;
$_SESSION['CASENUM'] = $_POST['CASENUM'];
?>

mcibor

3:36 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's see what's happening:

First you get $cfname from $_SESSION, then you get it from $_POST then you write it to $_SESSION. Let's call it 1), 2) and 3).

So when you submit the data cfname = "bla" is in the form and you post it. 1) is null, but 2) is "bla", you pass "bla" into 3).

Next you click save, which is not form:
1) you get "bla", 2) you erase "bla" and have null, 3) you write null to $_SESSION.

The solution to this problem would be using function isset

if(isset($_POST["cfname"])) $cfname = $_POST["cfname"];

That should do!
Michal Cibor