Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

PHP MySQL Update

In SQL, Update is another statement which is used to update any record of a table.

Ads

PHP MySQL Update

     

In SQL, Update is another statement which is used to update any record of a table. This command is useful when we need to update any existing value, which could be wrong or need to be updated.

General format of the command is as follows:

update <table name>

set <field-name=value,....>

where <condition>

In the above syntax where is important because if you do not use this every field will be changed.

Now let us implement this statement in PHP.

Example:

<?php

$db=mysql_connect("localhost","root","");

if(!$db)

{

die("Cannot connect".mysql_error());

}

mysql_select_db("roseindia",$db);

echo "<br/>Before updation:<br/>";

$result=mysql_query("select * from student");

while($row=mysql_fetch_array($result))

{

echo $row['e_id']." ".$row['age']."<br/>";

}

echo"<br/>After updation:<br/>";

mysql_query("update student set age=26 where e_id='emp01'");

$result=mysql_query("select * from student");

while($row=mysql_fetch_array($result))

{

echo $row['e_id']." ".$row['age']."<br/>";

}

mysql_close($db);

?>

Output:


Before updation:
emp01 28
emp02 27
emp05 26
emp_05 28

After updation:
emp01 26
emp02 27
emp05 26
emp_05 28

Advertisements

Share on Google+Share on Google+

PHP MySQL Update

Posted on: December 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: PHP MySQL Update   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
sameer
August 19, 2011
to clear doubt

i'v created a html form consist of fullname, emailid, username, password & also a link which displays all records into the database which i use to store the information like fullname.... etc..... the page displays records in a tabular format contains a column with edit button fo every single record. after clicking on edit button it again connect the main page but it doesn't display the selected record which i want to make changes. so can u help me.....

Ads

 

Ads