Answer the question
In order to leave comments, you need to log in
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>
<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
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 theforeach ( $_POST['item'] as $value ) echo "<li>$value</li>";
There are no errors in the given code. besides the fact that the hell you understand where you come from $item comes from .
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.
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 questionAsk a Question
731 491 924 answers to any question