MySQL Insert string type variable time, need to pay attention to the problem, mom, I think for several hours!!

Source: Internet
Author: User
Tags mysql insert

Many people find the following error when inserting data into a database using Php+mysql as a website:

Registration failed! Unknown column ' 1a ' in ' Field list '

It turns out that there is no problem with digital submissions, and other types of char are problematic.

Believe that the small partners and firmly believe that the SQL statement is not written wrong, then the problem is where.

Let's look at my SQL statement:

--inserting data into the user table (user and pass column),

$sql = "INSERT into user (User,pass) VALUES ($user, $pass)";

When we like int data time, SQL executes in the database is

Insert into User (User,pass) values (001,001);

When executing the char model data, however, the SQL statement becomes:

Insert into User (User,pass) values (ABC,ABC);

Now you can see the problem, the reason is the char type to add ' symbol.

Let's change the SQL statement to:

$sql = "INSERT into user (User,pass) VALUES ('". $user. "', '". $pass. "')";

Can.

MySQL Insert string type variable time, need to pay attention to the problem, mom, I think for several hours!!

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.