I use a <select>
list that gets data from a database. I need to choose from a list item and give it to the handler calc2.php but it does not work, because the list between tags <? php?>
<? php?>
and i cant assign <select action="calc2.php" name ="plant">
how to assign <select action="calc2.php" name ="plant">
when tags between the <? php?>
<? php?>
and send the selected item via the button <input type="submit" name="submit_all">
<fieldset>
<legend>Медоноси</legend>
<?php
if($text){
echo "
<select>
<option selected>Виберіть рослину зі списку</option>";
foreach($text as $item){
echo "
<option>".$item['plants_name']." ".$item['plants_prod']."</option>";
}
//закриваємо список
echo"</select>";
}
?>
<form action="calc2.php"name="distance" method="POST">
<br>Ведіть відстань до медоносу<br>
<input type="number" min="100" max="2000" step="50" name="distance"><br>
</fieldset>
<fieldset>
<legend>Бджолородини</legend>
<form action="calc2.php" name="bees" method="POST">
Кількість сімей на пасіці<br>
<input type="number" min="1" max="30" name="amount"><br><br>
Сила сімей<br>
<input type="number" min="8" max="24" name="power"><br>
<input type="submit" name="submit_all"> </form>
</fieldset>
The first <form>
doesn't close and a <form>...<form>...</form>
is invalid HTML
The inputs do not have a value attribute
<fieldset>
....
<form action="calc2.php"name="distance" method="POST">
<br>Ведіть відстань до медоносу<br>
<input type="number" min="100" max="2000" step="50" name="distance"><br>
</form> <!-- missing above ! -->
</fieldset>
<fieldset>
<legend>Бджолородини</legend>
<form action="calc2.php" name="bees" method="POST">
Кількість сімей на пасіці<br>
<input type="number" min="1" max="30" name="amount"><br><br>
Сила сімей<br>
<input type="number" min="8" max="24" name="power"><br>
<input type="submit" name="submit_all">
</form>
</fieldset>
Put your select under the form
<form action="calc2.php" name="bees" method="POST" **id=bees-form**>
and use the
<select name=plants form="bees-form">
to assign the select element to the form in order to get the select value through $_POST['plants'] in your calc2 php file.
you can read about it here
if you want to post all info at once keep it in 1 form. If i understood you correctly this should be the fix.
<form action="calc2.php" name="bees" method="POST">
<fieldset>
<legend>Медоноси</legend>
<?
if($text){ ?>
<select>
<option selected>Виберіть рослину зі списку</option>
<?
foreach($text as $item){
?>
<option><?=$item['plants_name']." ".$item['plants_prod'];?></option>
<?
}
?>
</select>
<?
}
?>
<br>Ведіть відстань до медоносу<br>
<input type="number" min="100" max="2000" step="50" name="distance"><br>
</fieldset>
<fieldset>
<legend>Бджолородини</legend>
Кількість сімей на пасіці<br>
<input type="number" min="1" max="30" name="amount"><br><br>
Сила сімей<br>
<input type="number" min="8" max="24" name="power"><br>
<input type="submit" name="submit_all"> </form>
</fieldset>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.