简体   繁体   中英

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.

Could you please help me with this? Here is 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++. 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 . The user can only select one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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