Php Sql Where

Ads
 

Php Sql Where

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

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:

Ads

Ads