A small problem of combining SQL statements in a single entry registration module-php Tutorial

Source: Internet
Author: User
A small question about the combination of SQL statements in the single-entry registration module: a registration class written in single-entry mode

$ Uname = $ _ POST ['uname'];
$ Pwd = md5 ($ _ POST ['pwd']);
// Combined SQL
$ SQL = "insert into user (username, password) values ($ uname, $ pwd )";
M ()-> exec ($ SQL );

$ SQL has a problem with inserting data. $ uname and $ pwd both get the value. which one I wrote is wrong. isn't double quotation marks directly capable of parsing variables?
// I changed this to direct insertion. No problem $ SQL = "insert into user (username, password) values ('xiaozhang', '123 ')";
$ SQL I changed to $ SQL = "insert into user (username, password) values (". $ uname. ",". $ pwd. ")"; no. what should I do if something goes wrong.


Reply to discussion (solution)

My debugging method is to write an insert statement in the database first. after the execution is successful, you can piece together the expressions on the php side according to the statements you have written.

$ SQL = "insert into user (username, password) values ('$ uname',' $ pwd ')";
Strings must be enclosed in quotation marks. Otherwise, they will be misunderstood.

$ SQL = "insert into user (username, password) values ('". $ uname. "','". $ pwd. "')"; when an error occurs, you can view the SQL output.

$ SQL = "insert into user (username, password) values ('$ uname',' $ pwd ')";
Strings must be enclosed in quotation marks. Otherwise, they will be misunderstood.



$ Uname is not a variable. why is it enclosed in single quotes? isn't single quotes in php not a variable not parsed?


$ SQL = "insert into user (username, password) values ('$ uname',' $ pwd ')";
Strings must be enclosed in quotation marks. Otherwise, they will be misunderstood.



$ Uname is not a variable. why is it enclosed in single quotes? isn't single quotes in php not a variable not parsed?



If your uname is defined as varchar without quotation marks, the SQL statement will report an error.



$ SQL = "insert into user (username, password) values ('$ uname',' $ pwd ')";
Strings must be enclosed in quotation marks. Otherwise, they will be misunderstood.



$ Uname is not a variable. why is it enclosed in single quotes? isn't single quotes in php not a variable not parsed?



If your uname is defined as varchar without quotation marks, the SQL statement will report an error.



My database defines the char (20) type

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.