Database add Data II and SQL statement errors

Source: Internet
Author: User
Tags function prototype

Some time ago, writing code (database add data i), adding data to the database is a very basic one to add. But when it comes to testing, it's not always possible to add test data one at a time, and then I try to add thousands of hundreds of at a time, but when I do it again, it's a problem. Because the ordinary reading, all just a glimpse, and the book is basically the function of the prototype, the function prototype is quite ' simple '! But it's easy to make mistakes when used, so write an article about how to add data to a database.

First build a users table in the test database, the users (UserID, username,userstatus), underline the primary key, and then start the operation, the code is shown below:

The first is the most commonly used "add one by one":

<! DOCTYPE html>

The

 insert.php code is as follows:

<! DOCTYPE html>
}?> </body> 

Note that when writing SQL statements, be sure to note the use of single and double quotes: for strings, you must enclose them in quotation marks, numbers can be used, or not. The most important point is that when double quotation marks and single quotation marks are used at the same time, be careful not to confuse, must follow "double quotation marks contain single quotation mark" or "single quotation mark contains double quotation mark", absolutely cannot below these three examples (all is wrong):

$sql = "INSERT into users set userid= $UserID, username=" $UserName ", userstatus= $UserStatus"; $sql = ' Insert to users set Userid= $UserID, username= ' $UserName ', userstatus= $UserStatus '; $sql = "INSERT into users set userid= $UserID, Username= ' $ UserName ", userstatus= $UserStatus";

Add multiple, code as follows:

<! DOCTYPE html>

Database add Data II and SQL statement errors

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.