PHP Freelancer

Freelance PHP Developer

Mysql Tutorial – Update data in to table

Posted on | March 8, 2009 | 2 Comments

Hello Friends,

If you are a learner (new) in PHP / Mysql and don’t know how to update / edit data in to table in Mysql database from php file than Here is the easiest and error-free way to update / modify data in to  table in Mysql database.

You can modify data using UPDATE query . here you are going to update record which is already exist . so you need to update record based on id or primary key. so dont forget to write WHERE clause in Update query . look at  the below code.

<?php
///*** This file will help you to update data in to tables in MYSQL database using PHP – Rakshit Patel **////

include(“mysql-connection.php”);

mysql_select_db(“testing”); // select database

$sql = “UPDATE test_table SET
name = ‘kate’,
email = ‘kate@gmail.com’,
message = ‘hiiii’ WHERE id = ’1′ “;

mysql_query($sql) or die(‘Error, update query failed’);

include(“mysql-connection-close.php”);
?>

Here first i have added mysql-connection.php file which will make connection with Mysql database. If you dont know how to make connection with Mysql database than click here.

Now i have selected Mysql database (named testing ). if you have not created database than click here.

After selecting database , you need to execute the query as written above to update record in to table. If you have not created table yet , than click here.

Thats it. Just check the record you have updated by using Select Query.

At last i have included mysql-connection-close.php file.

<?php ///*** This file will close MYSQL connection using PHP – Rakshit Patel **////

mysql_close($connection); // close mysql connection
?>

This is nothing but it will close connection which we have made earlier. Its not necessary but a sign of Good Programmer.

Cheers !!

      
Plugin by: PHP Freelancer

Comments

2 Responses to “Mysql Tutorial – Update data in to table”

  1. Dewaele
    March 21st, 2010 @ 6:09 am

    Hi,

    another less resource-hungry way to update multiple table rows and insert new rows at the same time is the INSERT INTO… ON DUPLICATE KEY UPDATE… that was introduced in MySql 4.1.

    feel free to read more about it on : http://www.od2dev.be/lang/en/mysql5-multiple-queries/

  2. Dancing Jobs London
    September 13th, 2011 @ 6:39 am

    Exotic Dancing London…

    [...]Mysql Tutorial – Update / edit / modify data in to table | Online Hungama[...]…

Leave a Reply





Freelance PHP Developer