How to Insert Data in Database using PHP OOPS Classes and Objects
Insert Data into database using classes and object.
Create database and table into you localhost server ( phpmyadmin )
Add fields that you require to insert, i'm doing here users related information name, email, contact, gender, education, address. When you done with table we can work on next step.
Create a form inside users.php file where we can get information from user to insert into database.
define('DB_HOST','localhost'); define('DB_USER','root'); define('DB_PASS',''); define('DB_NAME','demo'); class dbcon { public $con; public function __construct() { $this->con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME); } public function insertData($fname,$email,$contact,$gender,$education,$address) { $query = "INSERT INTO users(name,email,contact,gender,education,address)After that we can include the functions.php file inside our users.php and create our class object and called the insert function using class object. All things are done. Now go to your browser and run your users.php file and fill the form and click on submit and check your database table data is inserted. If you have any error contact me or message me.
values('$fname','$email','$contact','$gender','$education','$address')"; $result=mysqli_query($this->con,$query); return $result; } }
Comments
Post a Comment
If you have any error, bug related to your Prestashop website, Let me know