Home > Backend Development > PHP Tutorial > How to add data to the database using mysqli_PHP tutorial

How to add data to the database using mysqli_PHP tutorial

WBOY
Release: 2016-07-13 10:01:15
Original
1019 people have browsed it

How PHP uses mysqli to add data to the database

This article mainly introduces the method of PHP using mysqli to add data to the database. An example analysis of how PHP uses mysqli to perform database operations. Skills, very practical value, friends in need can refer to it

The example in this article describes how PHP uses mysqli to add data to the database. Share it with everyone for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

$mydb = new mysqli('localhost', 'username', 'password', 'databasename');

$sql = "INSERT INTO users (fname, lname, comments)

VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[comments]')";

if ($mydb->query($sql) == TRUE) {

echo "user entry saved successfully.";

} else {

echo "INSERT attempt failed" ;

}

$mydb->close();

1 2

3

4 5

67 8 9
$mydb = new mysqli('localhost', 'username', 'password', 'databasename'); $sql = "INSERT INTO users (fname, lname, comments) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[comments]')"; if ($mydb->query($sql) == TRUE) {
echo "user entry saved successfully."; } else { echo "INSERT attempt failed" ; } $mydb->close();
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/971952.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971952.htmlTechArticleHow PHP uses mysqli to add data to the database. This article mainly introduces how PHP uses mysqli to add data to the database. , an example analysis of PHP's use of mysqli for database operations...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template