E
E
Egor2016-02-18 11:09:35
PHP
Egor, 2016-02-18 11:09:35

Where is the error in the sample code written in PHP?

Hello! Please tell me where is the error in the code written in PHP?
Here is the form page:

<html>
  <head>
    <title>Список</title>
  </head>
  <body>
    <form name="form1" action="ex1.php" method="post">
      <select name="item" size="5">
        <option>Чай</option>
        <option>Кофе</option>
        <option>Молоко</option>
        <option>Ветчина</option>
        <option>Сыр</option>
      </select>
      <input type="submit" value="ВВОД">
    </form>
  </body>
</html>

And here is the action code in PHP:
<html>
  <head>
    <title>Обработка списка</title>
  </head>
  <body>
    <?
      echo "Ваш заказ: <p><ul>";
      foreach ( $item as $value ) echo "<li>$value</li>";
      echo "</ul>";
    ?>
  </body>
</html>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Silm, 2016-02-18
Repiev @ega22a

You forgot to specify what error you are getting. Or what is the actual problem.
replace
with
replace

foreach ( $item as $value ) echo "<li>$value</li>";
on the
foreach ( $_POST['item'] as $value ) echo "<li>$value</li>";

G
GreatRash, 2016-02-18
@GreatRash

There are no errors in the given code. besides the fact that the hell you understand where you come from $item comes from .

D
Dmitry Kovalsky, 2016-02-18
@dmitryKovalskiy

The select has a name attribute, but its options do not have a value attribute. I can't say anything about PHP - I don't know this language.

N
Nurlan, 2016-02-18
@daager

HZ what kind of error, maybe short_tags are not enabled in PHP? Or forgot to pass $_POST['item'] to the page as $item? Also "p" tag is not closed and option without value.
P.S. How about:

<html>
<head>
    <title>Обработка списка</title>
</head>
<body>
    Ваш заказ:
    <p>
    <ul>
        <?foreach ( $item as $value ) :?>
        <li><?=$value?></li>
        <?endforeach;?>
    </ul>
</body>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question