How to Update a Table in MySQL

A database helps to keep your information in order. The MySQL database management system helps you keep the hundreds or even thousands of records in your database organized and accessible with ease. Depending on the nature of the information in your database, you may need to update your data from time to time. Prices in a store change; students' grades need updating. You can change the values in your tables by using the UPDATE query. This SQL statement allows you to modify the information contained in your tables.

Instructions

    • 1

      Open your PHP file. Locate the the code that connects to your MySQL database. Check the variable that you have used to connect to it. For example, if your connection statement is "$connect = mysql_connect("localhost', 'mysql_username', 'mysql_password');" then "$connect" is your variable.

    • 2

      Type a statement to connect to your database on a new line. Use the "mysql_select_db("database_name", $connect);" query to select the database you want to update information from.

    • 3

      Enter "mysql_query("UPDATE table_name SET table_column='new_value' WHERE table_column='number'") or die(mysql_error());" to update your table. For example, to change the price of an item in a store's database, you would type "mysql_query("UPDATE prices SET cost='3.99' WHERE item='Milk'") or die(mysql_error());".

    • 4

      Close the connection to the database by typing "mysql_close($connect);" to stop modifying it.

    • 5

      Upload your PHP file to your server and run the page to execute the UPDATE query.

Tips & Warnings

  • You can update information in multiple tables by substituting "table_name" with "table_name1, table_name2, ..." for as many tables as you want to update.

  • Exclude the "WHERE" clause in the query to update each entry with a new value.

  • Do not confuse single quotation marks with double quotation marks or you will generate an error.

Related Searches:

References

Comments

You May Also Like

  • MySQL Joins Update Query Tutorial

    Sometimes updating information in a table requires information in a different table. MySQL lets you update the data in one table based...

  • How to Update Syntax for MySQL

    MySQL is a relational database that is optimized to hold data from a website. The "update" statement updates the columns of existing...

  • How to Perform an UPDATE MySQL Query

    Make sure that every ID in the table is unique by using an INTEGER AUTO_INCREMENT column. UPDATE commands can update the wrong...

  • How to Update & Increment MySQL

    MySQL (Structured Query Language) is a relational database management system that is utilized to manage information infrastructures and allow for multi-user access...

  • How to Update a Record in MySQL

    MySQL is an open-source database that is widely used in database-driven websites. In conjunction with programming languages such as PHP and ASP.net,...

  • How to Insert a Decimal in PHP MySQL

    PHP provides many standard functions for handling MySQL databases. This means that inserting data into a MySQL database table using a PHP...

  • How to Update Table Set COL

    An update statement is a SQL statement that is used to change the data in a set of database records. You can...

  • How to Change a MySQL Privilege Table

    There will be times when multiple users need to access the same database, at which point you will need to change the...

  • How to Reset MySQL 5.1 Root Password in Windows

    MySQL is a relational database management system that allows you to update, delete and process information. Free with on a number of...

  • MySQL PHP Query Tutorial

    You can use PHP to send queries to a MySQL database. PHP must be configured to use the MySQL client libraries during...

Related Ads

Featured