How to Insert Data in Database using PHP OOPS

How to Insert Data in Database using PHP OOPS

In this Post We Will Explain About is How to Insert Data in Database using PHP OOPS With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to fetch data from database in php using oops Example

In this post we will show you Best way to implement php mysql insert operation in PHP using OOP, hear for insert data in mysql using php class with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  Angular Grid Alternate row color Example

Setp 1.First create a html form

Index.php

	<form name="insert" action="" method="post">
       <table width="100%" border="0">
  <tr>
    <th width="26%" height="50" scope="row users">USER Full Name :</th>
    <td width="74%"></td>
  </tr>
  <tr>
    <th height="50" scope="row users">USER Email :</th>
    <td></td>
  </tr>
  <tr>
    <th height="50" scope="row users">USER Contact no. :</th>
    <td></td>
  </tr>
  <tr>
    <th height="50" scope="row users">USER Gender :</th>
    <td> Male   
	 Female</td>
  </tr>
   <tr>
    <th height="50" scope="row users">USER Education :</th>
    <td>
	Select Any one
	10th
	12th
	Graduate
	Post Graduate
	 </td>
  </tr>
  <tr>
    <th height="50" scope="row users">USER Address :</th>
    <td><textarea name="user_address" class="form-control">
	</textarea></td>
  </tr>
  <tr>
    <th height="50" scope="row users"> </th>
    <td></td>
  </tr>
</table>
 
     </form>

Setp 2. Create a database with name demos

Inside demos content data base make a table inserdata
Sample some Structure of user_mst table

CREATE TABLE IF NOT EXISTS `user_mst` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`phone` bigint(20) NOT NULL,
`user_gender` varchar(255) NOT NULL,
`user_edu` varchar(255) NOT NULL,
`user_user_address` longtext NOT NULL,
`posting_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

Setp 3. Create a php page function .php

Inside this simple page a using class DB_concreate or define. Db_con class contain simple database connection and some insert funtion.

function .php

Setp 4.Define a oject and class the insert funtion

Put this source code at the top of the simple root file index.php page

insert($user_fname,$email,$user_mobile,$user_gender,$user_edu,$adrss);
	if($sql)
	{
	echo "alert('USER Data inserted');";
	}
	else
	{
	echo "alert('USER Data not inserted');";
	}
}
 ?>

Example

I hope you have Got What is Objects Orientation in PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Advanced Laravel 5.7 Eloquent Queries Builder
  2. Read Also:  View Files with FileZilla - filezilla edit file on server
  3. Read Also:  JavaScript Clone Array Examples
  4. Read Also:  How to Insert Data Into MySQL Database Table Using PHP?
  5. Read Also:  Bash if else statement using Bash Scripting
  6. Read Also:  PHP OOPS - MySQL connecting Insert update delete select Fetch Data
  7. Read Also:  Laravel 5.7 Get Current Page URL path
  8. Read Also:  PHP Table Insert Tr After Every Third Loop
  9. Read Also:  AngularJS Fancybox Popup Simple Example
  10. Read Also:  jquery $.inArray Method with Example