CREATE TABLE IF NOT EXISTS `list` (
`sno` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`gender` varchar(10) NOT NULL,
`location` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
dbinsert.php <style type="text/css">
#register {
background:#9DBE78;
width:19.5%;
margin-left:15px;
border:groove
}
</style>
<script type="text/javascript" src="validation.js"></script>
<?php
$conn=mysql_connect("localhost","root","");
mysql_select_db("mytest",$conn);
@$name=$_POST['name'];
@$email=$_POST['email'];
@$password=$_POST['pwd'];
@$gender=$_POST['gender'];
@$location=$_POST['location'];
if(isset($_POST['register']))
{
$sql="insert into list(sno,name,email,password,gender,location) values('','$name','$email','$password','$gender','$location')";
$res=mysql_query($sql);
if($res)
{
echo "Inserted";
}
else
{
echo "Not Inserted";
}
}
?>
<div id="register">
<form method="post" name="register" action="" onSubmit="return validate()">
<table width="200" border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" id="pwd"></td>
</tr>
<tr>
<td>Gender:</td>
<td><input type="radio" name="gender" id="gender" value="male">Male
<input type="radio" name="gender" id="gender" value="female">FeMale
</td>
</tr>
<tr>
<td>Location:</td>
<td><select name="location" >
<option value="-1">Select</option>
<option value="delhi">Delhi</option>
<option value="vijayawada">Vijayawada</option>
<option value="bangalore">Bangalore</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="register" id="register" value="Insert"></td>
</tr>
</table>
</form>
</div>
validation.js
function validate()
{
var d=document.register;
if(d.name.value == "")
{
alert("Please Enter Name");
d.name.focus();
return false;
}
if(d.email.value == "")
{
alert("Please Enter Email");
d.email.focus();
return false;
}
if(d.pwd.value == "")
{
alert("Please Enter Password");
d.pwd.focus();
return false;
}
if(d.gender[0].checked == false && d.gender[1].checked == false)
{
alert("Please Select Gender");
return false;
}
if(d.location.value == -1)
{
alert("Please Select Location");
return false;
}
return true;
}
Inserted data in database table:
22:26
Share:
0 comments: