UPDATE statement is used to modify the data in the database table

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags data function mysql mysql tutorial mysql_query network network programming note
Update the data in the database

UPDATE statement is used to modify data in the database table.

Syntax UPDATE table_name SET column_name = new_value WHERE column_name = some_value

Note: SQL is not case sensitive. UPDATE and update equivalent.

In order for PHP to execute the above statement, we must use mysql_query (function. This function is used to send queries and commands to the SQL connection.

example

Earlier, we created a table named "Person" in this tutorial. It looks something like this:

FirstName LastName Age Peter Griffin 35 Glenn Quagmire 33

The following example updates some data for the "Person" table:

<? php $ con = mysql_connect ("localhost", "peter", "abc123"); if ($ con) {die ('Could not connect:'. mysql_error ());} mysql_select_db ("my_db", $ mysql_query ("UPDATE Person SET Age = '36' WHERE FirstName = 'Peter' AND LastName = 'Griffin'"); mysql_close ($ con);?>

After this update, the "Person" table looks like this:

FirstName LastName Age Peter Griffin 36 Glenn Quagmire 33

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.