So this is the second assignment in a beginner PHP class. One part of the assignment requires you to allow the user to enter in multiple walls in an HTML form (the program is a calculator to figure out the cost of paint, labor, etc.), however you don’t know how many walls the person is going to enter, so the form needs to be dynamic.
I don’t think we’re allowed to use javascript.
I’ve tried to use the SESSION variable to store the values into an array ( how to store variable values over multiple page loads ) and use foreach functions to loop and save the data ( How to store values from foreach loop into an array? ).
Nothing seems to be working. In this assignment we’re not supposed to use SQL.
Is there another way to store an array? I’d also be happy with a way to echo the data and leave it there until the cache is cleared.
Here’s the code I have right now (sorry it’s a bit of a mess):
print_r($_POST);
echo "<br />";
print_r($_REQUEST['wallW']);
echo "<br />";
echo "<br />";
$wallW = $_REQUEST['wallW'];
echo "The width is $wallW.";
echo "<br />";
print_r($wallW);
$_SESSION['wallW'] = $wallW;
$wallW = $_SESSION['wallW'];
?>
<form name="getOrderInfo" action="" onsubmit="" method="post">
<table id="wallInfo">
<th>
Order Information
<th>
<tr>
<td>
Wall Width:
</td>
<td>
<input type="text" name="wallW[]" id="wallW" size="20" value="">
</td>
<tr>
<tr>
<td>
Wall Length:
</td>
<td>
<input type="text" name="wallL[]" id="wallL" size="20" value="">
</td>
<tr>
</table>
<input type="submit" value="Add Wall">
</form>
Any help would be great.
Thanks,
Chelsea
Do you use
session_start();on the top of the file, then$_SESSION['array'] = $array;.