RE: Session and validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
>
> Here is the example:
>
> testarray (page1)
> //Start the session
> <?php session_start();
>
> //Check for the array on submit
> if ( empty( $_SESSION['l_industry'] ) ) {
> $_SESSION['l_industry']=array();
> }

$industry = $_POST['industry']; // ??

> //Check to make sure user didnt exceed 5 selections
> if (count($industry) > 5) {
>     echo "you have selected too many industries";
> 	exit;
> }

So, if this is the result of a form submission how are you getting the POST
variables?
How/where is $industry being set? I appears that you are assuming that
variables are 'maintained' within a script, they are not. You have to
remember that although you are running the same script it is not the same
'instance' of the script as a request/response has occurred. You MUST pass
and retrieve SESSION/POST/GET variables if you intend to use them in your
script.

$_SESSION['x'] = $_POST['x'];
$_SESSION['y'] = $_POST['y'];
etc etc...

> ?>
> <?php
> //Redirect to results page if user stayed in 5 option
> //range
> if ($_SERVER["REQUEST_METHOD"] == "POST") {
>  Header("Location:
> http://www.......com/TAresults.php";);
> }

You do not appear to have set the SESSION variables before redirecting to
the next page.

> ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
> Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <?php //PHP ADODB document - made with PHAkt 2.7.3?>
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> </head>
>
> <body>
> <table width="500" border="1" align="center"
> cellpadding="2" cellspacing="2">
>   <tr>
>     <td><form name="form1" id="form1" method="post"
> action="">

Not sure about this... have you used action="$PHP_SELF" ?

>       <select name="industry[]" size="10"
> multiple="multiple" id="industry[]">
>         <option value="1" <?php if (!(strcmp(1,
> "Please Select"))) {echo "SELECTED";}
> ?>>Accounting</option>
>         <option value="2" <?php if (!(strcmp(2,
> "Please Select"))) {echo "SELECTED";}
> ?>>Entertainment</option>
>         <option value="3" <?php if (!(strcmp(3,
> "Please Select"))) {echo "SELECTED";}
> ?>>label</option>
>         <option value="4" <?php if (!(strcmp(4,
> "Please Select"))) {echo "SELECTED";} ?>>Advertising
> </option>
>         <option value="5" <?php if (!(strcmp(5,
> "Please Select"))) {echo "SELECTED";} ?>>Customer
> Service</option>
>         <option value="6" <?php if (!(strcmp(6,
> "Please Select"))) {echo "SELECTED";} ?>>Informatin
> Technology</option>
>       </select>
>       <input type="submit" name="Submit"
> value="Submit">
>     </form></td>
>   </tr>
> </table>
> </body>
> </html>
>
> TAresults (page2):
>
> <?php session_start();
>
> if ( empty( $_SESSION['l_industry'] ) ) {
> $_SESSION['l_industry']=array();
> }
>
> if ( is_array( $_REQUEST['LurkerIndustry'] ) ) {
> $_SESSION['l_industry'] = array_unique(
> array_merge( $_SESSION['l_industry'],
>  $_REQUEST['LurkerIndustry'] )
> );
> }
> ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
> Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1" />
> <title>Untitled Document</title>
> </head>
>
> <body>
> <?php
> echo "The time is"."<br />";
> echo $industry['0']."<br />";
> echo $industry['1']."<br />";
> echo $industry['2']."<br />";
> echo $industry['3']."<br />";
> echo $industry['4']."<br />";
> echo $industry['5']."<br />";
> echo $industry['6']."<br />";
> echo $industry['7']."<br />";
> echo $industry['8']."<br />";
> echo $industry['9']."<br />";
> echo $industry['10']."<br />";
> echo $industry['11']."<br />";

Sorry, I cannot see where $industry is being set. This may just need

$industry = $_SESSION['industry'];

>
> ?>
> <?php
> unset($l_industry);
> ?>
> </body>
> </html>
>
> The results here, are whether the check passes or not
> the variables never echo.
> If I set action on page 1 to TAresults.php , then they
> echo out fine.
>
> Stuart
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux