Forum Moderators: coopster

Message Too Old, No Replies

Can't pass form variables

         

briesm

4:03 pm on May 31, 2005 (gmt 0)

10+ Year Member



Hey, I'm trying to use sessions with a post form to pass variables, add them to an array, and then call on the array to print them. But the array calls produce blank results. Here is what I have on my first php file to save a text field's value to a variable:
<?php
$field_qty1 = "";
if (isset($_SESSION['qty1'])) $field_qty1 = $_SESSION['qty1'];
elseif ($_POST['qty1']) {
$_SESSION['qty1'] = $_POST['qty1'];
$field_qty1 = $_SESSION['qty1'];
}
?>
<input type="text" name="qty1" size="5">

I'm going to be accessing variables via arrays...yet typing this:
$ordersArray = array();
array_push($ordersArray, $field_qty1);

then using:
<?php print $ordersArray[0];?>
will print blank. Any clue why? Using the above code allowed me to retrieve session variables from text fields but when I include arrays, I can't retrieve the info.

StupidScript

6:40 pm on May 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure why you're not seeing anything unless
$field_qty1
is empty when you're trying to add it to the end of the array. You are adding overhead by using
array_push()
.

You should consider easing your server's load by using:

[stuff that defines $field_qty1]

$ordersArray[]=$field_qty1;

to add the new value to the end of the array.