php my sql insert – Insert Data Into MySQL Using MySQLi and PDO – Inserting Data into a MySQL Database Table. This article displays you how to use the MySQL INSERT INTO SELECT statement to insert data into a table with example.
php my sql insert – PHP MySQL Insert Data
php my sql insert – PHP MySQL INSERT Query For insert data in MySQL first i have to make a table in data base. The INSERT INTO statement is used to insert new rows in a database table.
Here i using 3 main file for insert data in MySQL:
- db_config.php:For connecting data base
- insert.php:for getting the values from the member
- do_submit.php:A PHP file that process the request
Insert Data Into MySQL Using PHP
CREATE TABLE `member` ( `memberid` int(8) NOT NULL, `member_fname` varchar(55) NOT NULL, `member_lname` varchar(55) NOT NULL, `address` varchar(55) NOT NULL, `email` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
For connecting data base
db_config.php
for getting the values from the member
insert.php
A PHP file that process the request
do_submit.php
Alternative Code in (PDO)
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO member (member_fname,member_lname,address,email,datetime) VALUES ('$member_fname', '$member_lname','$address','$email','$insertdate')"; $link->exec($sql); echo "New member created successfully"; } catch(PDOException $e) { echo $sql . "
" . $e->getMessage(); } $link = null; ?>
Also Read: CRUD in PHP
I hope you get an idea about php my sql insert.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.