gpt4 book ai didi

php - 查询单选按钮到MYSQL数据库

转载 作者:行者123 更新时间:2023-11-30 22:19:39 26 4
gpt4 key购买 nike

我需要建议在 html 中使用单选按钮根据用户选择查询 MYSQL。

这个表叫做“Trainers”

一共有三个训练师:

  1. 克里拉维拉
  2. 诺瓦茨
  3. 尤里

用户选择他/她想要安排 session 的培训师。在 MYSQL 上,我想显示“krillavilla”与用户进行了“5”次会面,而“Urie”与用户进行了“0”次会面。

我研究了这篇文章: How can i add radio buttons record into MySQL fields using PHP但我试图避免数组

在这篇文章中: Inserting the selection of radio buttons into MySQL

没有回答我正在寻找的问题。

这是我的 php:

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost","******","******","*****");//This is the login creditial

if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());//Error check for execution
}

// Escape user inputs for security

$trainers = mysqli_real_escape_string($link, $_POST['trainers']);




// attempt insert query execution
$sql = "INSERT INTO trainers (trainers) VALUES ('$trainers')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// close connection
mysqli_close($link);

?>

这是我的 html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="test2.php" method="post">
<p>

<input type="radio" name="trainers" id="krillavilla">krillavilla
</p>
<p>

<input type="radio" name="trainers" id="Urie">Urie
</p>
<p>
<input type="radio" name="trainers" id="Novac">Novac
</p>
<input type="submit" value="Submit">
</form>
</body>us
</html>

这是我的第二个表单页面。我正在尝试使用三种形式的网页创建 GYM 时间表,用户将在其中:

注册成员(member)=> 用户选择培训师=> 用户选择他/她想要的成员(member)类型=> 确认页面

但现在我需要帮助弄清楚如何获取我的单选按钮数据以记录在 MYSQL 上分配给培训师的用户数量。

顺便说一句,我用过这个:

http://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

作为我的向导

最佳答案

  1. 您需要设置 value="Urie" 而不是 id="Urie"

关于php - 查询单选按钮到MYSQL数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37018259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com