Using PHP and Mysql, we can store data obtained from radio button into mysql table. The biggest reason for using Radio button is radio button allows user to select one option only i.e., limited options.
Create database ”data” and table “tb”.
CREATE TABLE `data`.`tb` (`name` VARCHAR( 25 ) NOT NULL , `color` VARCHAR( 5 ) NOT NULL) ENGINE = INNODB;
Using Global variable $_POST, we have to send data from HTML form into php script.
Here the PHP and HTML coding is to insert the data obtained from radio button into MySQL database using PHP script.
we have to give all input radio button as color (i.e., all radio buttons should have same radio button )
if($name!="" && $color!="")
$query=mysql_query("insert into tb values('$name','$color')");
echo "Updated successfully!";
echo "there is a problem in Databse";
echo "Please fill all details";
Which Color your like most?
<form method="post" action="index.php">
Name:<input type="text" name="name" /><br />
<input type="radio" name="color" >
User have to enter their name and their liked color. Both of this fields will be saved in database.
Thanks!. IF you like this article please don't forget to comment and share.