php 设置表单包括多个表格,表格中的多个表单,多个提交按钮。我可以用PHP和HTML做到吗?...

我正在为跆拳道学校创建一个时间表,我希望管理员能够删减他们的表格。

这是我想要的样子:

31Ec0.jpg

这是我现在的代码:

<?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?>

$schedules = Schedule::find_all();

?>

Schedule

if(isset($_POST['delete'])){

$schedule = Schedule::find_by_id($_GET['id']);

if($schedule && $schedule->delete()) {

$session->message("The line was deleted.");

redirect_to('schedule.php');

}else{

$session->message("The line could not be deleted.");

redirect_to('schedule.php');

}

}

?>

if(isset($_POST['submit'])){

$schedule = new Schedule();

$schedule->belt = $_POST['belt'];

$schedule->age = $_POST['age'];

$schedule->monday = $_POST['monday'];

$schedule->tuesday = $_POST['tuesday'];

$schedule->wednesday = $_POST['wednesday'];

$schedule->thursday = $_POST['thursday'];

$schedule->friday = $_POST['friday'];

$schedule->saturday = $_POST['saturday'];

if($schedule->save()) {

$session->message("line added successfully.");

redirect_to('schedule.php');

} else {

$message = join("<
", $schedule->errors);

}

}

?>

if(isset($_POST['update'])){

$schedule = Schedule::find_by_id($_POST['id']);

$schedule->belt = $_POST['belt'];

$schedule->age = $_POST['age'];

$schedule->monday = $_POST['monday'];

$schedule->tuesday = $_POST['tuesday'];

$schedule->wednesday = $_POST['wednesday'];

$schedule->thursday = $_POST['thursday'];

$schedule->friday = $_POST['friday'];

$schedule->saturday = $_POST['saturday'];

if($schedule->save()) {

$session->message("line updated successfully.");

redirect_to('schedule.php');

} else {

$message = join("<
", $schedule->errors);

}

}

?>

BeltAgeMondayTuesdayWednesdayThursdayFridaySaturday

<?php include_layout_template('admin_footer.php'); ?>我想做一些额外的增强功能,但我无法弄清楚这种形式。直到我添加了更新的功能之前,它工作得很好。现在,当我将一些新数据添加到其中一行时,然后单击更新 - 它不会给我一个会话消息,也不会更新视图中的字段(但我认为它在数据库中)。

任何意见,将不胜感激。我想我可以用一些AJAX来解决这个问题 - 但我一段时间没有碰到它,坦白地说,不记得如何...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个基本的 PHP 表单代码,其包含文本框、单选按钮、复选框、下拉式列表框和文本区域,并且在提交后将信息显示在表格。您可以根据自己的需要进行调整和修改。 ```php <!DOCTYPE html> <html> <head> <title>用户资料表单</title> <meta charset="UTF-8"> </head> <body> <h2>用户资料表单</h2> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <label for="name">姓名:</label> <input type="text" id="name" name="name"><br><br> <label for="gender">性别:</label> <input type="radio" id="male" name="gender" value="male"> <label for="male">男</label> <input type="radio" id="female" name="gender" value="female"> <label for="female">女</label><br><br> <label for="hobby">爱好:</label> <input type="checkbox" id="reading" name="hobby[]" value="reading"> <label for="reading">阅读</label> <input type="checkbox" id="music" name="hobby[]" value="music"> <label for="music">音乐</label> <input type="checkbox" id="travel" name="hobby[]" value="travel"> <label for="travel">旅游</label><br><br> <label for="city">所在城市:</label> <select id="city" name="city"> <option value="beijing">北京</option> <option value="shanghai">上海</option> <option value="guangzhou">广州</option> <option value="shenzhen">深圳</option> </select><br><br> <label for="comment">个人简介:</label> <textarea id="comment" name="comment" rows="5" cols="50"></textarea><br><br> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> <br><br> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $gender = $_POST["gender"]; $hobby = $_POST["hobby"]; $city = $_POST["city"]; $comment = $_POST["comment"]; echo "<table border='1'>"; echo "<tr><td>姓名:</td><td>$name</td></tr>"; echo "<tr><td>性别:</td><td>$gender</td></tr>"; echo "<tr><td>爱好:</td><td>"; foreach ($hobby as $value) { echo "$value "; } echo "</td></tr>"; echo "<tr><td>所在城市:</td><td>$city</td></tr>"; echo "<tr><td>个人简介:</td><td>$comment</td></tr>"; echo "</table>"; } ?> </body> </html> ``` 注意:这只是一个简单的示例,实际应用需要考虑更多的细节和安全性问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值