Home Tutorial Php Sql Php Sql Where

 
 

Share on Google+Share on Google+
Php Sql Where
Posted on: December 10, 2010 at 12:00 AM
Advertisement
This example illustrates how to use the WHERE clause in the UPDATE query in PHP.

Php Sql Where

This example illustrates how to use the WHERE clause in the UPDATE query in PHP.

In this example we create a UPDATE query with WHERE clause to update the field emp_name where name is 'amar'. In the figure below the first figure show before update the table and the second figure show after update the table.

 

Table: emp_table before update

 

Table: emp_table after update

 

Source Code of update_where.php 

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

  mysql_select_db("test", $con);

  $update = "UPDATE emp_table SET emp_name = 'sandeep' WHERE emp_id = 1";

  mysql_query($update, $con);

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

  $result = mysql_query("SELECT * FROM emp_table");

  while ($row = mysql_fetch_array($result)) {
      echo "<br>";
      echo $row['emp_id'] "<br>";
      echo $row['emp_name'] "<br>";
      echo $row['emp_designation'] "<br>";
      echo "<br>";
    }

  mysql_close($con);
?>

Download Source Code

 

Output:

Advertisement

Related Tags for Php Sql Where:


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: December 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com