Monday 26 November 2012

Php code to update values in database

Lets see how we can use php mysql to update values in the database,

Database connection and other related facts are discussed earlier, so let move on to update directly,

Syntax: update <table_name> set <field1>='[update value]' where [condition 1][condition 2]....

See this demo,

id   |  name
1       Rogg
2       Hoggs
3       Brad

In the above that we need to update the name 'Hoggs' with 'Hopes',

<?php
     $update = "update test_table set name='Hopes' where id=2";
     $result   = mysql_query($update);
?>

The statement will result in updation of the record with id is '2'.

Thank You.

No comments:

Post a Comment