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.
Read also: How To: Submit Form When Radio Button is Clicked [Without Submit button]
Create database “data” and table “tb”.
[code type=html]
CREATE TABLE
`data`.`tb` (`name` VARCHAR( 25 ) NOT NULL ,
`color` VARCHAR( 5 ) NOT NULL)
ENGINE = INNODB;
[/code]
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 )
index.php
[code type=php]
<html>
<body>
<?php
if(isset($_POST[‘submit’]))
{
$name=$_POST[‘name’];
$color=$_POST[‘color’];
if($name!=”” && $color!=””)
{
$query=mysql_query(“insert into tb values(‘$name’,’$color’)”);
if($query)
{
echo “Updated successfully!”;
}
else
{
echo “there is a problem in Databse”;
}
}
else
{
echo “Please fill all details”;
}
}
else
{
?>
Which Color your like most?
<br />
<form method=”post” action=”index.php”>
Name:<input type=”text” name=”name” /><br />
<input type=”radio” name=”color” value=”Red” />Red
<input type=”radio” name=”color” value=”Green” />Green
<input type=”radio” name=”color” value=”Black” />Black
<input type=”radio” name=”color” value=”White” />White
<input type=”submit” name=”submit” />
</form>
<?php
}
?>
</body>
</html>
[/code]
User have to enter their name and their liked color. Both of this fields will be saved in database.
Hi i need help to put a radio button (true -false quiz) to my sql database table , can you show me the direction please ?i need help for my assignment , Thanks
thanks
Great , thank you very much . that what is look for
realy helpfull
thank you….very helpul
Is it possible to post three times or more on the same page?
could u please explain briefly, i can’t understand
There’s certainly a great deal to find out about this issue.
I really like all of the points you’ve made.