Php 将选择选项中的值保存到数据库

Php 将选择选项中的值保存到数据库,php,Php,所以我试图在我的数据库中插入一些数据,不幸的是它没有像我希望的那样工作。 这是我的index.php文件,我在这里编写了一段php代码,以从数据库中获取select选项(这很好)。但现在我希望人们从我的数据库中的选项中进行选择,并将所选选项存储在另一个db表中 <?php $query = "SELECT event_naam FROM events"; $result2 = mysqli_query($dbconn, $query); $options = ""; while($r

所以我试图在我的数据库中插入一些数据,不幸的是它没有像我希望的那样工作。 这是我的index.php文件,我在这里编写了一段php代码,以从数据库中获取select选项(这很好)。但现在我希望人们从我的数据库中的选项中进行选择,并将所选选项存储在另一个db表中

<?php
$query = "SELECT event_naam FROM events";

$result2 = mysqli_query($dbconn, $query);

$options = "";

while($row2 = mysqli_fetch_array($result2))
{
    $options = $options."<option>$row2[0]</option>";
}
?>
<form class="inschrijven" method="POST" action="includes/inscscript.php">
    <select name="iselect">
        <?php echo $options;?>
    </select><br><br>
    <span>Uw Naam: </span><input type="text" name="inaam" placeholder="Naam"><br>
    <span>Leeftijd: </span><input type="number" name="leeftijd"><br>
    <span>Aantal Personen:</span><input type="number" name="personen"><br>
    <input type="submit" name="inschrijven" value="Inschrijven!">
</form>



Uw Naam:
Leeftijd:
南极人:
我已经试过了,但是没有任何效果,也没有出现错误

require_once 'connectie.php'; //Connection to Database File

$sql = "INSERT INTO inschrijven (inschrijf_event, inschrijf_naam, inschrijf_leeftijd, inschrijf_personen) VALUES 
('".$_POST['iselect']."','".$_POST['inaam']."','".$_POST['leeftijd']."','".$_POST['personen']."')";

if ($dbconn->query($sql) === TRUE) {
 header( "Location: ../index.php" );
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $dbconn->error."');</script>";
}

$dbconn->close();
require_once'connectie.php'//连接到数据库文件
$sql=“插入inschrijven(inschrijf_事件、inschrijf_naam、inschrijf_leeftijd、inschrijf_personen)值
(“$”POST['iselect']。”、“$”POST['inaam']。”、“$”POST['leeftijd']。”、“$”POST['personen']。”);
if($dbconn->query($sql)==TRUE){
标题(“位置:../index.php”);
}否则{
echo“警报('Error:'.$sql.
“$dbconn->Error.”);”; } $dbconn->close();
这是我的inscscript.php文件

我试着搜索类似的qeustions,但找不到类似的东西

$query=“从事件中选择事件”;
$query = "SELECT event_naam FROM events";
$result=mysqli_query($con,$query)
  {
  // Return the number of rows in result set
  while($rowcount=mysqli_num_rows($result)){
echo "<option value='".$rowcount['event_naam']."'>".$rowcount['event_naam']."</option>
}
$result=mysqli\u查询($con,$query) { //返回结果集中的行数 while($rowcount=mysqli_num_rows($result)){ 回显“.$rowcount['event\u naam']” }
在选择opend和结束标记之间将此php文件包含到html中

使用$options=$options.“$row2[0]”为选项赋值