NYCPHP Meetup

NYPHP.org

[nycphp-talk] Passing info entered into HTML FORMS intoSESSIONvariables.

PaulCheung paulcheung at tiscali.co.uk
Thu Nov 29 16:37:09 EST 2007


Thanks Micheal,
Thanks to you it appears to be working now, the coding is true, the 
information is being passed

Here is the coding for "tp_update_tr.php" which is being used to verify info 
passing (messy and not elegant but useful for testing)
<?PHP SESSION_START(); ob_start();
$self         = $_SERVER['PHP_SELF'];
$referer      = $_SERVER['HTTP_REFERER'];
$access       = $_SESSION['access'];
$nr0          = $_SESSION['nr0'];
$testno       = $_SESSION['testno'];

$actualdata         = $_POST['actualdata'];
$actualresult       = $_POST['actualresult'];
$testnote           = $_POST['testnote'];
$_SESSION['actualdata']   = $actualdata;
$_SESSION['actualresult'] = $actualresult;
$_SESSION['testnote']     = $testnote;

echo('TP_UPDATE_TR.PHP'                 . "<BR>");
echo('================' .                 "<BR>");
echo('$self = ' . $self         . "<BR>");
echo('$referer =  ' . $referer      . "<BR>");
echo('$access = ' . $access       . "<BR>");
echo('$nr0 = ' . $nr0          . "<BR>");
echo('$testno = ' . $testno       . "<BR>");
echo('$actualdata = ' . $actualdata   . "<BR>");
echo('$actualresult = ' . $actualresult . "<BR>");
echo('$testnote = ' . $testnote     . "<BR>");
PHP?>




----- Original Message ----- 
From: "Michael Southwell" <michael.southwell at nyphp.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Wednesday, November 28, 2007 11:12 PM
Subject: Re: [nycphp-talk] Passing info entered into HTML FORMS 
intoSESSIONvariables.


> 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 
>> populate a HTML page (all working OK) At the bottom of the page I open an 
>> HTML FORM the idea being the user may enter what they want and when they 
>> hit "SUBMIT" the info is POSTED to an UPDATE_DB subroutine.
>
> Right here is where you are going wrong, unless what you have posted below 
> is not an accurate representation of what you are doing. The action in 
> your form is tp_update_tr.php and that is the *only* script where the 
> $_POST variables are available.  You are (or appear to be from the code 
> below) attempting to use them in the same script as the form. You need two 
> scripts, a form script and a form-processor script.
>
> [yes, I know you can do this in one script, but this is a good example of 
> the issue raised earlier this afternoon about the occasional necessity for 
> the simple version of an explanation.]
>
>
> The
>> HTML FORMS just does not work and I cannot see why not.
>>
>> <?PHP session_start(); ob_start(); $access = $_SESSION['access']; PHP?>
>> <HTML>
>> <?PHP include("count.js"); ?>
>> </SCRIPT>
>>
>> HTML & PHP CODING
>> HTML & PHP CODING
>> HTML & PHP CODING
>> HTML & PHP CODING
>>
>> EVERYTHING WORKING AS EXPECTED AND REQUIRED UPTO THIS POINT
>> At this point I want the users to enter data and click "SUBMIT" which all 
>> happens as expected. AT this point here is the FORMS coding
>>
>> <FORM ACTION="tp_update_tr.php" ID="primary" METHOD="post">
>> <TABLE BOARDER="0">
>> <TBODY>     <TR bgcolor="#cccccc">
>>          <TD width="180">DESCRIPTION</TD>
>>          <TD width="50"> </TD>
>>          <TD width="740"><CENTER>MAXIMUM FIELD LENGTHS 
>> APPLY</CENTER></TD></TR>
>>      <TR><TD>ACTUAL OUTPUT:</TD>
>>          <TD><INPUT disabled="count" name="actualdata_ct" size="2" 
>> value="128"></TD>
>>          <TD><TEXTAREA name="actualdata" cols="106" 
>> rows="2"></TEXTAREA></TD></TR>
>>      <TR><TD>ACTUAL RESULT:</TD>
>>          <TD><INPUT disabled="count" name="actualresult_ct" size="2" 
>> value="255"></TD>
>>          <TD><TEXTAREA name="actualresult" cols="106" 
>> rows="3"></TEXTAREA></TD></TR>
>>      <TR><TD>TEST NOTE :</TD>
>>          <TD><INPUT disabled="count" name="testnote_ct" size="2" 
>> value="255"></TD>
>>          <TD><TEXTAREA name="testnote" cols="106" 
>> rows="3"></TEXTAREA></TD></TR>
>>         </TBODY>
>> </TABLE>
>> <?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>");}
>> ?>
>> </TABLE>
>> <TABLE BOARDER="0">
>> <TBODY>     <TR><TD width="180"> </TD>
>>          <TD width="50" > </TD>
>>          <TD width="760"> </TD></TR>
>>                    <TR><TD><a href="tp_mainmenu.php" 
>>  ><BUTTON>EXIT</BUTTON></a>
>>                        <a href="#" onclick="window.print()"><?PHP echo(' 
>> | '); PHP?><BUTTON>Print</BUTTON></a></TD>
>>                        <TD><input value="UPDATE - 163" 
>> type="submit"></TD></TR>
>>         </TBODY>
>>
>> </BODY>
>> </TABLE>
>> </FORM>
>> </HTML>
>>
>> ----- Original Message ----- From: "Michael Southwell" 
>> <michael.southwell at nyphp.com>
>> To: "NYPHP Talk" <talk at lists.nyphp.org>
>> Sent: Sunday, November 18, 2007 9:02 PM
>> Subject: Re: [nycphp-talk] Passing info entered into HTML FORMS into 
>> SESSIONvariables.
>>
>>
>>> PaulCheung wrote:
>>>>        $t = $row['data']; $u = $row['result']; $v = $row['note'];
>>>
>>> How are you populating the $row array?  I would have expected this to 
>>> be:
>>>     $t = $_POST['data'];
>>> Doing it this way you should have no problem. And by the way, you don't 
>>> need the $t etc variables unless you are using them elsewhere. That 
>>> would make it this:
>>>     $_SESSION['data'] = $_POST['data'];
>>>
>>> -- 
>>> =================
>>> Michael Southwell
>>> Vice President, Education
>>> NYPHP TRAINING:  http://nyphp.com/Training/Indepth
>>> _______________________________________________
>>> New York PHP Community Talk Mailing List
>>> http://lists.nyphp.org/mailman/listinfo/talk
>>>
>>> NYPHPCon 2006 Presentations Online
>>> http://www.nyphpcon.com
>>>
>>> Show Your Participation in New York PHP
>>> http://www.nyphp.org/show_participation.php
>>
>> _______________________________________________
>> New York PHP Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> NYPHPCon 2006 Presentations Online
>> http://www.nyphpcon.com
>>
>> Show Your Participation in New York PHP
>> http://www.nyphp.org/show_participation.php
>>
>
>
> -- 
> =================
> Michael Southwell
> Vice President, Education
> NYPHP TRAINING:  http://nyphp.com/Training/Indepth
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 




More information about the talk mailing list