// Make a file config.php
<?php
error_reporting(0);
mysql_connect("localhost","root","");
mysql_select_db("dbmusic");
?>
//Make a file reg_data.php
<?php include("config.php");
$gender= $_POST['gender'];
$hobbies = implode(",",$_POST["hobbies"]);
$insert = mysql_query("insert into radio_check(radio,checkbox) values('$gender','$hobbies')");\
if($insert)
{
header("location:index.php?msg=succ");
}
else
{
header("location:index.php?msg=error");
}
?>
// Make a file index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Radio And CheckBox</title>
</head>
<body>
<h1 align="center">Radio & Check Box With Database</h1>
<form action="reg_data.php" method="post">
<table border="1" align="center" >
<br /><br />
<tr>
<td colspan="2" align="center" style="color:#000; background:#666"> Enter your information here </td>
</tr>
<tr>
<td>Gender</td>
<td>Male<input type="radio" name="gender" value="male" >
Female <input type="radio" name="gender" value="female">
</td>
</tr>
<tr>
<td>Hobbies:</td>
<td>
Cooking :
<input type="checkbox" name="hobbies[]" value="Cooking">
Dance:
<input type="checkbox" name="hobbies[]" value="Dance">
Magic:
<input type="checkbox" name="hobbies[]" value="Magic">
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit" style="background:#666; color:#000" ></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if($_GET["msg"]=="error")
{
echo "<h2> Data Not Insert</h2>";
}
if($_GET["msg"]=="succ")
{
echo "<h3 align=center>Data Insert</h3>";
}
?>
// Make database
-- Database Name : `dbmusic`
--
-- Table Name : `radio_check`
-- --------------------------------------------------------CREATE TABLE IF NOT EXISTS `radio_check` (
`id` int(25) NOT NULL AUTO_INCREMENT,
`radio` varchar(25) NOT NULL,
`checkbox` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
-- Dumping data for table `radio_check`
INSERT INTO `radio_check` (`id`, `radio`, `checkbox`) VALUES
(1, 'male', 'Cooking,Dance'),
(2, 'female', 'Cooking,Dance'),
(7, 'male', 'Cooking,Dance,Magic');
No comments:
Post a Comment