Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
 
 


 

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:

                         

» View all related tutorials
Related Tags: sql mysql c sed type column exec state name set exe define if execute statement to modify proc e alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.