MySQL Forums
Forum List  »  PHP

Add code edit delete in php
Posted by: Wade Simpson
Date: July 09, 2017 05:17AM

To add data you use the INSERT INTO statement, the code sample is as follows:
<? Php

Require 'database.php';
$ Ho_ten = 'Nguyen Duc Anh';
$ Tuoi = '26';
$ Gioi_tinh = 'Nam';
$ Query = "INSERT INTO guests
                               (Hoten, tuoi, gioitinh)
                               ('$ Ho_ten', '$ tuoi', '$ gioi_tinh') ";
$ Result = $ db-> exec ($ query);

Explanation: In the code above I have inserted the table named guest value is $ ho_ten in the hoten column, $ age in the age column, $ gioi_tinh into the gender column.

When adding data there are always two big questions:

Add data to where
Add something with value like?
The answer is full in the $ query variable:
Add data to the guest table with columns that are hot, fresh and juicy
The corresponding values ​​are $ ho_ten, $ tuoi and $ gioi_tinh.
Specific values ​​are $ ho_ten corresponding Nguyen Duc Anh, $ tuoi is 26, $ gioi_tinh is South.
Finally $ result = $ db-> exec ($ query) will proceed to write the data to the table. There is a small question, where is the $ db? What is the meaning of it?
$ Db represents the database, before calling the $ db variable you have to connect to the database, it is located directly to the first line:
Require 'database.php';
What is the content of the database.php file, please read the article: Connect MySQL database with PHP to run trial at Localhost.

Content database.php file is very important, any behavior that affects the database must use it.

Options: ReplyQuote

Written By
Add code edit delete in php
July 09, 2017 05:17AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.