PHP Note seven: PHP operation MySQL table (insert data)

Source: Internet
Author: User

1. SQL statements Used

INSERT into table name (field list) VALUES (list of values), (value list) ...;

Attention:

1), the field list to correspond to the Value List 2), when inserting data into all the fields in the table, you can omit the field list

2. Example:

<?PHP//insert data into table//Include connection database file (two methods, require is more strict than include, if the path is not reported serious error)//include ' conn.php ';    require' Conn.php '; //Assemble SQL statements that insert data    $sql= "INSERT into students (STUNAME,STUSEX,STUBIRTH,CLASSID) VALUES (' Tom1 ', default, ' 1987-05-08 ', 1)"; //$sql = "INSERT into Test (STUNAME,STUSEX,STUBIRTH,CLASSID) VALUES (' Jane ', default, ' 1988-05-08 ', 2), (' Nancy ', 0, '        1999-5-12 ', 3) "; Execute SQL statement    if(mysql_query($sql)){        Echo"<br> Insert Data Success"; }Else{        Echo"<br> failed to insert data"; }        //To close a database connection    Mysql_close($link);?>

 

PHP Note seven: PHP operation MySQL table (insert data)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.