PHP Append data to MySQL

Source: Internet
Author: User
Tags php mysql
Append data php mysql

PHP Append data to MySQL

In MySQL, a table in user has a field in name
There is already a record in the table
ID field value is 1
The value of the name field is "Week"
I now want to append "Jay" two words to this field
That is, the value of the name field of this record from the original "Week" Into the present "Jay"
How would you like to operate it?
How do I write code?
In code
$sql = "Update user set name = name + ' Jay ' where id= ' 1 '";
mysql_query ($sql);
The value of the Name field later becomes "0".


Reply to discussion (solution)

Dizzy Death
It turns out that.
$sql = "Update user set Name=concat (name, ' Jay ') where tid= ' 1 '";
mysql_query ($sql);

$sql = "Update user set name = ' Jay Chou ' where id= ' 1 '";

$sql = "Update user set name = ' Jay Chou ' where id= ' 1 '";

You're just going to change the name field to "Jay Chou".
Instead of appending "Jay" to the back of "Week".
method is not the same,
To the actual application can not play the same effect.

Well, then use Concat.

  • 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.