Welcome to Techno Smarter QA, Question, Answer forum. Ask questions, receive answers, or help someone. Join Now
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the Technical & Programming related questions that you want. Join our community and help others .
+4 votes

Hello Friends 

I Want to insert value using HTML radio button in PHP with MYSQL database . For example -

If i check male radio button then male value should be insert into mysql database and if i check female radio button then female value should be insert into the database . 

My Mysql database structure . 

I am attaching screenshot for PHP code . 

This operation is related to inserting data using html radio button . 

in PHP by (90 points) 3 18 31

2 Answers

+2 votes

If you want to add a radio button then you should create a form with radio button. 

For example - 

<input type="radio" name="ab" value="Male">Male 

<input type="radio" name="ab'" value="Female"> Female

Use PHP code and POST radio data using POST method 


Insert this $gender variable value into the database. 

Note -

1. The radio button name should the same for both. 

2. Use the radio button name to insert data by POST Method 

by (9.1k points) 12 25 63
edited by
Give me more reference.
No need to attach JAVA screenshot if you are working on PHP . Create a simple html form with two radio buttons . Provide same name for both radio button . like ab , ab or gen gen .

Like - ab name for first radio button
           ab name for second radio button

 Value should be different

Provide value for male       value="male"
 Provide vale for female radio button  value="female"

Use post method to handle form value and insert into database using insert query .

Follow the simple process ..


+1 vote

Thanks for the question here. I am here to help you. You are not described well with your HTML and PHP code. You should not include a code screenshot. You should include code only with description. I am understanding your concern. You want to insert radio button data like gender male or female in the database using PHP and MYSQL database. It's really simple. 

Let's follow the steps - 

How to insert data using the radio button in PHP? 

Step 1 - First of all create a database using the query 

CREATE TABLE  `data` (

 `id` INT( 50 ) NOT NULL ,

 `name` VARCHAR( 40 ) NOT NULL ,

 `gender` VARCHAR( 30 ) NOT NULL ,


In the query above, I created three-columns and a table name . We use the gender column and will insert male or female values.

Step 2- Now you need to create an HTML form with one input box and two radio buttons. 

Let's have a look - 

<form action="" method="post"


<input type="text" name="name"><br><br>

Gender :-

<input type="radio" name="gender" value="Male">Male 

<input type="radio" name="gender" value="Female">Female 

<input type="submit" value="Submit" name="submit">


Step 3- If you want to insert gender in database, you have to create PHP code with MYSQL query

Let's create a PHP script to insert gender Male or Female in PHP. 


$databaseHost = 'localhost';

$databaseName = 'records'; 

$databaseUsername = 'root'; 

$databasePassword = '';  

$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);



$name = $_POST['name'];

$gender = $_POST['gender'];

$result = mysqli_query($mysqli,"insert into data values('','$name','$gender')");



echo "Data inserted ";



echo "Something wrong";




Execute the code above. In this way, you can insert gender male or female in the database. 

If you have another issue, you can discuss in the comment. 

by (7.2k points) 14 29 62
It works.
I want to say that - Thanks for it.