PHP OOPs CONCEPT TUTORIAL

How to Insert data in Database Using PHP OOPs CONCEPT

Written by admin
CREATE TABLE `student_details` (
  `id` int(11) NOT NULL,
  `name` varchar(100) DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  `contact_no` varchar(45) DEFAULT NULL,
  `gender` varchar(45) DEFAULT NULL,
  `qualification` varchar(45) DEFAULT NULL,
  `address` varchar(450) DEFAULT NULL,
  `create_date` timestamp NULL DEFAULT current_timestamp()
)

DATABASE CONNECTION

<?php
define("DEMO_PORT","3306");
define("DEMO_CharSet","utf8");
define("DEMO_USER",'root');
define("DEMO_HOST",'localhost');
define("DEMO_PASS",'');
define("DEMO_DB","student");
?>

index.php

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<div class="container">
        <div class="row centered-form">
        <div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
        	<div class="panel panel-default">
        		<div class="panel-heading">
			    		<h3 class="panel-title">Please sign up for Bootsnipp <small>It's free!</small></h3>
			 			</div>
			 			<div class="panel-body">
			    		<form method="POST" action="insert.php">
			    			
                            <div class="form-group">
			    				<label for="name">Name</label>
			    				<input type="text" name="name" id="name" class="form-control input-sm" placeholder="Name" required="">
			    			</div>
			    			<div class="form-group">
			    				<label for="email">Email</label>
			    				<input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address" required="">
			    			</div>
			    			<div class="form-group">
			    				<label for="contactno">Contact No</label>
			    				<input type="text" name="contactno" id="contactno" class="form-control input-sm" placeholder="Contact No" required="">
			    			</div>
			    			<div class="form-group">
			    				<label for="name">Gender</label>
			    				<input type="radio" name="gender" value="Male">Male<input type="radio" name="gender" value="Female">Female
			    			</div>
			    			<div class="form-group">
			    				<label for="qualification">Qualification</label>
			    				<select name="qualification" id="qualification" class="form-control input-sm" placeholder="Qualification" required="">
			    					<option value="NA">--select--</option>
			    					<option value="10th">10th</option>
			    					<option value="12th">12th</option>
			    					<option value="Graduation ">Graduation</option>
			    				</select>
			    			</div>
			    			<div class="form-group">
			    				<label for="name">Address</label>
			    				<textarea name="address" id="address" class="form-control input-sm" required=""></textarea>
			    			</div>
                               <input type="submit" name="submit" value="submit" class="btn btn-info btn-block">
			    		
			    		</form>
			    	</div>
	    		</div>
    		</div>
    	</div>
    </div>
    <style type="text/css">
    	body{
    background-color: #fff;
}
.centered-form{
	margin-top: 60px;
}

.centered-form .panel{
	background: rgba(255, 255, 255, 0.8);
	box-shadow: rgba(0, 0, 0, 0.3) 20px 20px 20px;
}
    </style>

insert.php

<?php 
include 'DBConnect/MysqliDb.php';  
$succMsg= NULL;
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$contactno = $_POST['contactno'];
$gender = $_POST['gender'];
$qualification = $_POST['qualification'];
$address = $_POST['address'];
$classs = "insert into student_details(name, email, contact_no, gender, qualification, address) 
values('".$name."','".$email."','".$contactno."','".$gender."','".$qualification."','".$address."')";
$myDB =  new MysqliDb();
$query = $myDB->rawQuery($classs);
$mysql_error = $myDB->getLastError();
if($myDB->count >0){
echo  "Data is  successfully sent";
}

else{
echo "Data is Not successfully sent";
}
}
?>

About the author

admin

Hi there! I'm Shiv Gupta. I specialized in building Websites. I write blogs in my free time. I really like to find out and share my knowledge with others.I founded ThePhpConcept in March 2020. I started this blog in order that I can interact with some like-minded people and also help people learning PHP, Mysql, jQuery, Html, and PHP Projects and related technologies.
Support-thephpconcept@gmail.com

1 Comment

  • in this site is very simple way easy and clarity all posts programmes.
    where is crude operation in myasql not a pdo.
    please .upload crude operation .
    Thanku sir

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.