Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

PHP MySQL Update


PHP mysql_query() function is used to update record in a table. Since PHP 5.5, mysql_query() function is deprecated. Now it is recommended to use one of the 2 alternatives.

  • mysqli_query()
  • PDO::__query()

PHP MySQLi Update Record Example

Example

  1. <?php
  2. $host = ‘localhost:3306’;
  3. $user = ;
  4. $pass = ;
  5. $dbname = ‘test’;
  6. $conn = mysqli_connect($host$user$pass,$dbname);
  7. if(!$conn){
  8.   die(‘Could not connect: ‘.mysqli_connect_error());
  9. }
  10. echo ‘Connected successfully<br/>’;
  11. $id=2;
  12. $name=“Rahul”;
  13. $salary=80000;
  14. $sql = “update emp4 set name=\”$name\”, salary=$salary where id=$id”;
  15. if(mysqli_query($conn$sql)){
  16.  echo “Record updated successfully”;
  17. }else{
  18. echo “Could not update record: “. mysqli_error($conn);
  19. }
  20. mysqli_close($conn);
  21. ?>

Output:

Connected successfully
Record updated successfully

Comments

comments