First you create data base which name “employee” and then create table “oops” which fields name “id, name, address, mobile”.
And file save name with oops.php
<html>
<head>
<title>OOPs</title>
</head>
<?php
define(‘DB_SERVER’,’localhost’);
define(‘DB_USER’,’root’);
define(‘DB_PASS’ ,”);
define(‘DB_NAME’, ’employee’);
class DB_con
{
function __construct()
{
$conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die(‘localhost connection problem’.mysql_error());
mysql_select_db(DB_NAME, $conn);
}
public function insert($id,$name,$address,$mobile)
{
$res = mysql_query(“INSERT oops VALUES(‘$id’,’$name’,’$address’,’$mobile’)”);
return $res;
}
public function select()
{
$res=mysql_query(“SELECT * FROM oops”);
return $res;
}
}
?>
<body>
<div>
<form method=”post”>
Id:<br>
<input type=”text” name=”id”><br><br>
Name:<br>
<input type=”text” name=”name”><br><br>
Address:<br>
<input type=”text” name=”address”><br><br>
Mobile:<br>
<input type=”text” name=”mobile”><br><br>
<input type=”submit” name=”submit” value=”submit”>
</form>
<div>
<?php
include_once ‘oops.php’;
$con = new DB_con();
// data insert code starts here.
if(isset($_POST[‘submit’]))
{
$id = $_POST[‘id’];
$name = $_POST[‘name’];
$address = $_POST[‘address’];
$mobile = $_POST[‘mobile’];
$con->insert($id,$name,$address,$mobile);
header(“Location: show.php”);
}
// data insert code ends here.
?>
</body>
</html>
Thanks for this useful material provided by such a
great man known as “Ravi Verma”
thanks a lot
LikeLike