Question about the quotation marks for PHP operations on Mysql Query-php Tutorial

Source: Internet
Author: User
Update & nbsp; user & nbsp; set & nbsp; name $ _ POST [newname] [codephp] & nbsp; where & nbsp ;; and update & nbsp; user & nbsp; set & nbsp; name $ _ POST [newname] & nbsp; w quotation marks on Mysql Query operations in PHP
"update user set name='$_POST[newname][code=php]' where id=$_SESSION[id]";

And
"update user set name=$_POST[newname] where id=$_SESSION[id]";

What is the difference ?? (More and less single quotes)

This is a MySql statement for updating the user name. I asked the program to output $ sqlstr and found that the output results are the same in the above two cases,:

Today, we found that when there are no single quotes, we can update the name only when the new name is a number, with single quotes, Chinese characters and numbers are easy to use in English. if you don't know what to ask, ask for answers...

Also, I think the code written by my classmates is more complicated sometimes. it seems that I have added something like {} to the corresponding position, and I don't know how to use it ..

The next Cainiao .. Please give me a great answer .. Thank you very much ..
------ Solution --------------------
The character type must be enclosed by quotation marks-this is the most basic and questionable.
------ Solution --------------------
1. the ''of the SQL statement is used to indicate that a constant is a string.
Update user set name = 'Andy 'where id = 3
In this case, an error is reported.
Update user set name = Andy where id = 3
Depends on the type you set during table design.

2. the simpler the code, the better without affecting the function.


------ Solution --------------------
Let's take a look at the basics and practice more.
------ Solution --------------------
The characters must be enclosed in quotation marks. Numbers do not matter

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.