Grouping Form Selections Help

Discussion in 'PHP' started by gobbly2100, Apr 8, 2009.

  1. #1
    Hey there,

    I am learning some basic PHP but I can't quite understand why this tutorial I am following is not appearing to work.

    Here is the code:

    
    
    <?php
    
    if (!$_POST['submit']) {
    
    ?>
    
    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
    	<select name="options[]" multiple>
    		<option value"central locking">Central Locking</option>
    		<option value"steering lock">Steering Lock</option>
    		<option value"abs">ABS</option>
    		<option value"traction control">Traction Control</option>
    		<option value"remote locking">Remote Locking</option>
    	</select>
    	<input type="submit" value="Submit!" name="submit" />
    	<input type="reset" value="Reset" />
    </form>
    
    <?php
    }
    
    else {
    
    	if (is_array($_POST['options'])) {
    	
    		echo "<p>Here is your selection</p>";
    		echo "<ul>";
    		foreach ($_POST['options'] as $o) {
    					
    			echo "<li>" . $o . "</li>";
    		}
    		echo "</ul>";
    	}
    	
    	else {
    		echo "Nothing Selected";
    	}
    
    }
    ?>
    
    Code (markup):
    I have copied the code from the tutorial so I am a little lost about what is wrong, I just let 2 li tags but no array actually show as text.

    I hope someone can help, thank you!
     
    gobbly2100, Apr 8, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    <option value"central locking">
    you are missing "="
    <option value="central locking">
     
    javaongsan, Apr 8, 2009 IP
  3. gobbly2100

    gobbly2100 Banned

    Messages:
    906
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply, I actually saw it after some head scratching.

    It is kinda funny how when you focus on learning something new you forget some stuff you knew before without thinking.

    Thanks again!
     
    gobbly2100, Apr 8, 2009 IP