Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_POST from option box

    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:
    Code:
    <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:
    Code:
    <?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.

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Try...
    PHP Code:
    <?php

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

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Code:
    <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>

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    PHP Code:
    echo 'execution reached here <br/>';
    var_dump($_POST); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Try
    PHP Code:
    echo 'execution reached here <br/>';
    var_dump($_POST); 
    Returns
    Code:
    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?

  • #7
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    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:

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •