...

View Full Version : $_POST from option box



noobcoder643
03-16-2009, 01:02 AM
I am trying to get the value of an option box using POST but it doesn't get through to PHP. I have checked in firebug and it gets posted but PHP wont receive it. Here is my code.

index.php:


<form name="shutdown" method="POST" action="scripts/shutdown.php">
<table border="0">
<tr>
<td colspan="3"><b>Shutdown</b></td>
</tr>
<tr>
<td rowspan="4"><img src="images/icons/shutdown.png"></td>
<td>Time:</td>
<td>
<select name="time">
<option value="0">0:00</option>
<option value="10">0:10</option>
<option value="30">0:30</option>
<option value="60">1:00</option>
<option value="120">2:00</option>
<option value="300">5:00</option>
<option value="600">10:00</option>
</select>
</td>
</tr>
<tr>
<td>Message:</td>
<td><input type="text" name="message" size="40"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Shutdown"/></td>
</tr>
</table>
</form>


scripts/shutdown.php:


<?php
echo($_POST["time"]);
?>


I get no output. It works fine if I change post to get and posting text fields works fine. I can't see the problem.

All help is much appreciated. Thanks.

Iszak
03-16-2009, 02:45 AM
Try...


<?php

session_start();
echo $_POST['time'];

milanchheda
03-16-2009, 05:04 AM
I think, on first click of submit nothing will be posted to the shutdown.php as there is no value selected in the listbox.
keep the first value as selected b default and then proceed.


<select name="time">
<option value="0" selected>0:00</option>
<option value="10">0:10</option>
<option value="30">0:30</option>
<option value="60">1:00</option>
<option value="120">2:00</option>
<option value="300">5:00</option>
<option value="600">10:00</option>
</select>

noobcoder643
03-16-2009, 08:50 AM
Thanks but neither idea worked. I don't think it's a problem with the submission form as I can see in my firebug console that the data gets posted.

abduraooft
03-16-2009, 08:54 AM
Try

echo 'execution reached here <br/>';
var_dump($_POST);

noobcoder643
03-16-2009, 08:19 PM
Try

echo 'execution reached here <br/>';
var_dump($_POST);

Returns


execution reached here
array(2) { ["Content-Type:_application/x-www-form-urlencoded Content-Length:_21 time"]=> string(3) "120" ["message"]=> string(4) "Test" }


Why do I get the URL encoded content type?

thesavior
03-17-2009, 12:11 AM
You did a var dump, not an array print. Var dump gives you all the information about the variable, including type and other random information. print_array() gives you the key-> value keys and all the other data information you need.

if you just want to see what is contained in $_POST then you can do this:



echo "you are here";
echo "<pre>".print_array($_POST)."</pre>";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum