实际上我想开发一个应用程序,用户可以在其中设置学生的出勤率。所以出勤的 html 表单将来 self 的数据库查询。它也即将到来,但问题是我如何将该表单信息插入到我的数据库中。实际上我搜索了很多,但我没有得到任何像我想要的那样完美的结果,我的意思是请任何人都可以帮助我。提前致谢
<form action="attendance.php" method="post">
<?php include '../database-config.php';
foreach($dbh->query("SELECT * FROM student WHERE active_class='VII'") as $row){
echo "<div>
<label>".htmlentities($row['student_id'])."</label>
<input type='radio' name='atten".htmlentities($row['student_id'])."' checked='checked'>Present
<input type='radio' name='atten".htmlentities($row['student_id'])."'>Absent
</div></br>";
}
?>
<button type="submit" class="btn btn-success btn-lg">Submit</button>
<button type="reset" class="btn btn-danger btn-lg">Reset</button>
</form>
最佳答案
<form action="attendance.php" method="post">
<?php include '../database-config.php';
$result = mysql_query("SELECT * FROM student WHERE active_class='VII'");
foreach($result as $row)
{
?>
<div>
<label><?php echo $row['student_id']?></label>
<input type="radio" name="attend" value="present" checked>Present
<input type="radio" name="attend" value="absent">Absent
</div>
</br>
<?php
}
?>
<button type="submit" class="btn btn-success btn-lg">Submit</button>
<button type="reset" class="btn btn-danger btn-lg">Reset</button>
</form>
所以在 php 中你可以得到这样的值
<?php
$attend = $_POST['attend'];
echo $attend;
?>
因此在$attend
中它包含单选按钮的值(value="present"
)。
它可能存在
或不存在
关于php-mysql 从 echo 单选按钮插入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508914/