Free download web templates, books and more. Free php projects ,games and apps. GTA mods and more

Breaking

php mysqli update data in database

PHP MySQL Update Data (or) Record

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';  
  3. $user = 'root';  
  4. $pass = '';  
  5. $dbname = 'test';  
  6.   
  7. $conn = mysqli_connect($host$user$pass,$dbname);  
  8. if(!$conn){  
  9.   die('Could not connect: '.mysqli_connect_error());  
  10. }  
  11. echo 'Connected successfully<br/>';  
  12.   
  13. $id=4;  
  14. $name="sam";  
  15. $salary=80000;  
  16. $sql = "update staff set name=\"$name\", salary=$salary where id=$id";  
  17. if(mysqli_query($conn$sql)){  
  18.  echo "Record updated successfully";  
  19. }else{  
  20. echo "Could not update record: ". mysqli_error($conn);  
  21. }  
  22.   
  23. mysqli_close($conn);  
  24. ?>  
Output:
Connected successfully
Record updated successfully