Single entry registration module A small problem of combining SQL statements

Source: Internet
Author: User
Ask everyone a question, a registration class written in a single entry way

$uname =$_post[' uname '];
$pwd =md5 ($_post[' pwd ');
Combined SQL
$sql = "INSERT into user (Username,password) VALUES ($uname, $pwd)";
M ()->exec ($sql);

$sql There is a problem with inserting the data, both $uname and $pwd are getting the value. Which mistake did I write, the double quotation marks are not directly able to parse the variable?
I changed it to this direct insert no problem $sql= "insert into User (Username,password) VALUES (' Xiaozhang ', ' 34345 ')";
$sql I change to $sql = "INSERT into user (Username,password) VALUES (". $uname. ",". $pwd. ")"; Also not, where the error, should be how to write.


Reply to discussion (solution)

My debugging method, first go to the database to write an INSERT statement, after successful execution, according to your written statements to piece together the PHP side of the expression on the line.

$sql = "INSERT into user (Username,password) VALUES (' $uname ', ' $pwd ')";
Strings need to be enclosed in quotation marks, otherwise they will be misunderstood

$sql = "INSERT into user (Username,password) VALUES ('". $uname. "', '". $pwd. "')"; SQL output can be used to see what happens when something goes wrong.

$sql = "INSERT into user (Username,password) VALUES (' $uname ', ' $pwd ')";
Strings need to be enclosed in quotation marks, otherwise they will be misunderstood



$uname is not a variable, why enclose it in single quotation marks. is the single quotation mark in PHP not an unresolved variable?


$sql = "INSERT into user (Username,password) VALUES (' $uname ', ' $pwd ')";
Strings need to be enclosed in quotation marks, otherwise they will be misunderstood



$uname is not a variable, why enclose it in single quotation marks. is the single quotation mark in PHP not an unresolved variable?



If you uname defined as varchar, no home quotes, SQL will error.



$sql = "INSERT into user (Username,password) VALUES (' $uname ', ' $pwd ')";
Strings need to be enclosed in quotation marks, otherwise they will be misunderstood



$uname is not a variable, why enclose it in single quotation marks. is the single quotation mark in PHP not an unresolved variable?



If you uname defined as varchar, no home quotes, SQL will error.



My database defines the type of char (20)
  • 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.