简体   繁体   English

单选按钮仅将1个值插入SQL数据库

[英]Radio button inserts only 1 value into SQL database

I have a simple form that should insert radio button value into database: 我有一个简单的表格,应该将单选按钮值插入数据库:

<form method="post" action="insert.php">
 <input type="radio" name="yes" value="1"/>Yes<br />
 <input type="radio" name="yes" value="0"/>No
<input type="submit" name="submit" value="Send"/><br />
</form>

However, in the database, there is always inserted only value 1. 但是,在数据库中,总是只插入值1。

Could you please help me with this? 你能帮我这个忙吗? Here is insert.php 这是insert.php

$var = mysqli_real_escape_string($con, $_POST['yes']);

$sql="INSERT INTO table (value)
VALUES ('$var')";

Kindly thank you for advice. 谢谢您的建议。

We Use Radio Buttons To Send One Data Only. 我们使用单选按钮仅发送一个数据。 If you want to use multiple data, use checkbox. 如果要使用多个数据,请使用复选框。

Checkboxes are mainly use when presenting the user with a number of options, of which, they can select more than one option. 复选框主要用于向用户显示多个选项时,可以选择多个选项。 For example, Like courses-> PHP, Java, C#, C, C++. 例如,类似courses-> PHP, Java, C#, C, C++. The user can check multiple courses. 用户可以检查多个课程。

But, Radio buttons are generally used when presenting the user with an "either/or" option. 但是,当向用户显示“或者/或者”选项时,通常使用单选按钮 The user is presented with two or more options, of which, the user can only select one option. 向用户显示两个或多个选项,其中,用户只能选择一个选项。 For Example, Like Gender-> Male or Female . 例如,例如Gender-> Male or Female The user can only select one. 用户只能选择一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM