[nycphp-talk] Passing info entered into HTML FORMS into SESSIONvariables.
David Krings
ramons at gmx.net
Wed Nov 28 20:03:04 EST 2007
PaulCheung wrote:
> I am have a real problem with HTML FORMS and I cannot see where I am
> going wrong. I make a MySQL call and bring back the required data and
> <?PHP
> echo("<tr><td align='right' colspan=2>$prv");
> if ($cps == $nr0)
> { echo " | <font color='CCCCCC'> Next - 135</font>"; }
> else
> { if ($nr0 > 1)
> { echo(" | <a
> href='help_tp_update.php?cps=$cps&lps=$lps'><BUTTON>Next
> 138</BUTTON></a>"); }
> }
> echo(" - <B>(Record $x of $y)</B>");
> $_SESSION['testno'] = $h;
> $actualdata = $_POST['actualdata'];
> $actualresult = $_POST['actualresult'];
> $testnote = $_POST['testnote'];
> $_SESSION['actualdata'] = $actualdata;
> $_SESSION['actualresult'] = $actualresult;
> $_SESSION['testnote'] = $testnote;
> if ($v != null)
> { echo("<BR><B>PREVIOUS TESTNOTE: </B>" . $v . "<BR>");}
> ?>
I assume the above is the script that receives the data via $_SESSION,
correct? Is that all in one file or is that PHP code quoted above in a new
file? I recommend splitting things either into separate files or into
individual functions that get called from a switch statement. If you do the
latter get an IDE with code folding so that you can get a handle on the
mammouth file. The reason for this is either separating logic from the display
portion or creating functional blocks that can be easily tested.
My guess is that you cannot access $_SESSION because you did not pick up the
session with session_start() the second time around. Any time you have a
script that wants to get something from or write something to $_SESSION you
need to start or continue a session. You do not need to specify the session ID
upon restart, PHP figures that out for you.
I recommend replacing your db update script with this cheesy test code:
<?php
session_start();
echo "<pre>".$_SESSION."</pre>";
?>
That prints out the contents of $_SESSION. If there is nothing or not the
expected in there then setting the values in $_SESSION failed.
Also,
> </TABLE>
> <TABLE BOARDER="0">
has an "A" to many in "BOARDER", but that shouldn't be the cause for the
failure with the session.
Further, I do not see any of the variables getting initialized. I also cannot
see what the content of $v is supposed to be. I recommend that you use
descriptive variable names and add commentary to your source code. There is
nothing commented and that is one reason why you probably have a tough time
with finding the problem. Lastly, one nice way to track values is making use
of a debugger. I even spent money on an IDE with a decent debugger
implementation although I am a cheap bastard when it comes to software.
David
More information about the talk
mailing list