PHP Insert/Store Radio Button Clicked value to MySQL database

How to send radio button selected value to MySQL database using php.

Radio button is used to get multiple type of only single value from user in PHP. It will help the website admin to request some information regarding to its user and you have mostly seen radio button to ask any submission form to Male-Female and Like-Dislike websites. So here is the complete step by step tutorial for PHP Insert/Store Radio Button Clicked value to MySQL database.

android-project-download-code-button

PHP Insert/Store Radio Button Clicked value to MySQL database.

Code for radio-button-to-db.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Insert/Store Radio Button Clicked value to MySQL database</title>
</head>

<body>

<h3>PHP Insert/Store Radio Button Clicked value to MySQL database</h3>
 <form method="post" action="">
 <input type="radio" name="like" value="Like"><label>Like</label><br/>
 <input type="radio" name="like" value="DisLike"><label>DisLike</label><br/>
 <input type="radio" name="like" value="Average"><label>Average</label><br/>
 <input type="submit" name="submit" Value="submit">
 </form>

<?php

include 'dbconfig.php';

if (isset($_POST['submit']))
{
 $radio = $_POST["like"];
 $query = "INSERT INTO demo_table_3 (likevalue) VALUES ('".$radio."')";
 
 mysql_query($query) or die(mysql_error());
 
 echo "Successfully submitted";
 }

?>

</body>
</html>

Code for dbconfig.php file.

 <?php

//Define your host here.
$hostname = "localhost";

//Define your database username here.
$username = "root";

//Define your database password here.
$password = "";

//Define your database name here.
$dbname = "test";

 $conn = mysql_connect($hostname, $username, $password);
 
 if (!$conn)
 
 {
 
 die('Could not connect: ' . mysql_error());
 
 }
 
 mysql_select_db($dbname, $conn);



?>

Screenshot:

PHP Insert/Store Radio Button Clicked value to MySQL database

Click here to download PHP Insert/Store Radio Button Clicked value to MySQL database project source code file with SQL file included.

Leave a Reply

Your email address will not be published. Required fields are marked *