Let me explain further. I have a select form on my first php page (lets call this page first.php). I do have a submit button. I am catching the array on the second page (lets cal this page sec.php) with $_POST and then setting it to a PHP variable. However, I can not get it to print. Here's what my code/mark up looks like on first.php
<label>Product:</label>
<select name="arr[]">
<option value="Mobile">Mobile</option>
<option value="Social">Social</option>
<option value="Online">Online</option>
</select>
Note = I know I don't need to have an array for this. But I want to keep it this way.
Here's what my code looks like on sec.php:
<?php
$arr= $_POST['arr'];
?>
I want it to print in this HTML table:
<tr>
<td width="200"> <?php echo $url[0]; ?></td>
<td width="200"> <?php echo $sMonth[0] . "/" . $sDay[0] . "/" . $sYear[0]; ?></td>
<td width="200"> <?php echo $eMonth[0] . "/" . $eDay[0] . "/" . $eYear[0]; ?></td>
<td> <?php echo $tBudget[0]; ?></td>
<td> <?php echo $dBudget[0]; ?></td>
<td> <?php echo $model[0]; ?></td>
<td> <?php echo $bid[0]; ?></td>
<td> <?php echo $target[0]; ?></td>
<td> <?php echo $status[0]; ?></td>
<td width="200"> <?php echo $arr[0]; ?></td>
<td> <?php echo $tUnits[0]; ?></td>
</tr>
NOTE = all other variables and values print just FINE (by using the same method and concept as the $arr variable) But ONLY the $arr variable is unable to print).
What am I doing wrong?
Change
<select name="arr[]">
...
<td width="200"> <?php echo $arr[0]; ?></td>
to
<select name="arr">
...
<td width="200"> <?php echo $arr; ?></td>
You'll only want to use array naming
when you have a multiple select option
Actually, it's probably something like that:
<select name="arr[]" multiple>
<option value="Mobile">Mobile</option>
<option value="Social">Social</option>
<option value="Online">Online</option>
</select>
u need to use for loop to get values in your array check this
<form action="<?php echo @$_SERVER['PHP_SELF'];?>" method="POST">
<select name="arr[]" multiple>
<option>Radio</option>
<option>TV</option>
<option>Keyboard</option>
<option>DVD Player</option>
<option>Screen</option>
</select>
<input type="submit" value="GO!">
</form>
<?php
$data=@$_POST['arr'];
$len = count($data); // getting length of ur array that u need to condition ur loop
for($y=0;$y<$len;$y++){
echo "$data[$y]"."<br />";
}
?>
</div>