Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Mysql-update PHP SQL Update

Related Tutorials


 
 

Share on Google+Share on Google+

PHP SQL Update

Advertisement
PHP SQL Update is used to execute the mysql _update () function that modify the table structure and set the new value for the existing value on the condition specified in Where Clause.

PHP SQL Update

     

PHP SQL Update is used to execute the mysql _update () function that modify the table structure and set the new value for the existing value on the condition specified in Where Clause.

Understand with Example

 This example illustrates an example from 'PHP SQL Update'. To understand and grasp the example we create a update query "UPDATE emp_table SET emp_name = 'amar' WHERE emp_name = 'sandeep' AND emp_designation = 'programmer'". The update table is used to modify any field value of any MySQL table in PHP.

Syntax: The SQL syntax of UPDATE command is used to perform update data into MySQL table:

 

 

UPDATE table_name SET field1=new-value1, field2=new-value2[WHERE Clause]
  • The UPDATE query is used to modify one or more field all together.

  • The WHERE clause is used to specify any condition.

  • You can update values in a single table at a time.

The WHERE clause is very useful when you want to update selected rows in a table.

 

Table: emp_table

 

Table: emp_table

 

Source Code of sql_update.php 

<?php
  $con = mysql_connect("localhost","root","root");
  if (!$con){
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);

  mysql_query("UPDATE emp_table SET emp_name = 'amar' WHERE emp_name 

  = 'sandeep' AND emp_designation = 'programmer'");

  echo "Column emp_name updated successfully<br><br>";

  $result = mysql_query("SELECT * FROM emp_table");
  echo "<table border='1'>
  <tr>
  <th>ID</th>
  <th>Name</th>
  <th>Designation</th>
  </tr>";
  while ($row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['emp_id'] "</td>";
  echo "<td>" . $row['emp_name'] "</td>";
  echo "<td>" . $row['emp_designation'] "</td>";
  echo "</tr>";
  }
  echo "</table>";

  mysql_close($con);
?>

Download Source Code

Output:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 3, 2006

Related Tutorials

Discuss: PHP SQL Update  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com