InsertDemo.html
my_sql2.php
<html>
<head>
<title>
Insert Demo</title>
</head>
<body>
<h1
style="text-align:center;color:Indigo">Insert data in mysql using php </h1>
<form
method="POST" action="my_sql2.php">
<table
border="1">
<tr>
<td>ID
:</td><td> <input type="number"
name="id"/></td></tr>
<tr>
<td>Name:</td><td><input
type="text" name="name" required/></td></tr>
<tr>
<tr>
<td>D.O.B</td><td><input
type="date" name="dt"/></td></tr>
<td>Email:</td><td><input
type="email" name="email"/></td></tr>
<tr>
<td>Phone:</td><td><input
type="number" name="phone"/></td></tr>
<tr>
<td>Address:</td><td>
<textarea name="addr" rows="3"
cols="30"></textarea></td></tr>
<tr>
<td>Qualification:</td><td>
<select
name="Qualification">
<option
value="BE">BE</option>
<option
value="MCA">MCA</option>
<option
value="B.Sc">B.Sc</option>
<option
value="M.Sc">M.Sc</option>
<option
value="Other">Other</option>
</select></tr>
</table><br>
<input
type="submit" name="insert" value="Insert">
</form>
</body>
</html>
my_sql2.php
?php
$servername =
"localhost";
$username =
"root";
$password =
"";
$dbname=
"enquiry";
$conn = new
mysqli($servername, $username, $password, $dbname);
if(isset($_POST['subtn']))
{
$name1=$_POST['name'];
$email1=$_POST['email'];
$phone1=$_POST['phone'];
$addr1=$_POST['addr'];
$qual=$_POST['Qualification'];
$sql= "INSERT INTO student VALUES('$name1', '$email1', '$phone1','$addr1', '$qual')";
if(!mysqli_query($conn,$sql))
{
die('Error'.mysqli_error($conn));
}
else
{
echo '<script
language="text/javascript">';
echo '<alert
("Sucessfully registered");
//location.href="my_sql.html">';
echo
'</script>';
}
}
?>
Output:
Insert data in mysql using php
No comments:
Post a Comment