Hi, i am trying to create an html form including select element and reading input from in listing 9.4, but it can not function. The problem is after i fill in the form, select the item in the form and click the button, it will link to the page listing9.5.php, but the listing9.5.php page show blank.

below are the codes:

listing9.4.php
<html>
<head>
<title>Listing 9.4 An HMTL form including a SELECT element</title>
</head>
<body>
<form action="listing9.5.php" method="POST">
Name: <br>
<input type="text" name="user">
<br>
Address: <br>
<textarea name="address" rows="5" cols="40"></textarea>
<br>
Pick Products: <br>
<select name="products[]" multiple>
<option>Sonic Srewdriver</option>
<option>Tricoder</option>
<option>ORAC AI</option>
<option>HAL 2000</option>
</select>
<br><br>
<input type="submit" value="hit it!">
</form>
</body>
</html>

listing9.5.php
<html>
<head>
<title>Listing 9.5 Reading input from the form in Listing 9.4</title>
</head>
<body>
<?php
print "Welcome <b>$POST['user']</b><p>\n\n";
print "Your address is:<p>\n\n<b>$
POST['address']</b><p>\n\n";
print "Your product choices are:<p>\n\n";
if (!empty($POST['products'])) {
print "<ul>\n\n";
foreach ($
POST['products'] as $value){
print "<li>$value\n";
}
print "</ul>";
}
?>
</body>
</html>

i already try to add ' ' for the array element, but still not working. So, anyone know the reason? Thanks in advance. 🙂

    <html>
    <head>
    <title>Listing 9.5 Reading input from the form in Listing 9.4</title>
    </head>
    <body>
    <?php
    print "Welcome <b>{$_POST['user']}</b><p>\n\n";
    print "Your address is:<p>\n\n<b>{$_POST['address']}</b><p>\n\n";
    print "Your product choices are:<p>\n\n";
    if (!empty($_POST['products'])) {
    print "<ul>\n\n";
    foreach ($_POST['products'] as $value){
    print "<li>$value\n";
    }
    print "</ul>";
    }
    ?>
    </body>
    </html> 

    You have to have brackets around the variable in that case, most likely your servers php.ini settings are set to not show errors which meant you got a blank page 🙂

      ya, it's works! may i know when i should put {} because i saw you just remain some of the statement eg:
      ($_POST['products'] as $value)
      may i know how to change the php.ini setting to show the errors?
      thanks. 🙂

        You only need to use them when using echo() or print() unless you assign them to a variable, such as:

        $variable = $_POST["variable"];

        print "test $variable";

        In your php.ini look for the line that says

        error_reporting =

        also look for the line that says:

        display_errors =

        The default for error reporting is

        error_reporting = E_ALL & ~E_NOTICE
        display_errors = On

          o..thanks. actually i have tried many times with the code then just post here. Thanks again. 🙂

            Write a Reply...