Advertisement
Guest User

Untitled

a guest
Dec 25th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <?php
  2. //1. create a database connection
  3. $dbhost = "localhost";
  4. $dbuser = "widget_cms";
  5. $dbpass = "funkyguy";
  6. $dbname = "widget_corp";
  7. $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  8. // Test database connection
  9. if(mysqli_connect_errno()) {
  10. die("database connection failed: " .
  11. mysqli_connect_error() .
  12. "(" . mysqli_connect_errno() . ")"
  13. );
  14. }
  15. ?>
  16. <?php
  17.  
  18. //this are the form values from $_POST
  19. $id = 6;
  20. $menu_name = "Delete me";
  21. $position = 4;
  22. $visible = 1;
  23.  
  24. //2. perform database query
  25. $query = "UPDATE subjects SET ";
  26. $query .= "menu_name = '{$menu_name}', ";
  27. $query .= "position = {$position}, ";
  28. $query .= "visible = {$visible}, ";
  29. $query .= "WHERE id = {$id}";
  30.  
  31. echo $query;
  32.  
  33. $result = mysqli_query($connection, $query);
  34. // test if there was a query error
  35. if($result) {
  36.  
  37. echo "success";
  38. }else {
  39. die(" Database query failed: " . mysqli_error($connection));
  40. }
  41. ?>
  42.  
  43. <!doctype html>
  44. <html lang="en">
  45.  
  46. <head>
  47. <title>Database</title>
  48. </head>
  49.  
  50. <body>
  51.  
  52.  
  53.  
  54. </body>
  55. </html>
  56.  
  57. <?php
  58. //5. Close the connection
  59. mysqli_close($connection);
  60. ?>
  61.  
  62. $query = "UPDATE subjects SET ";
  63. $query .= "menu_name = '{$menu_name}', ";
  64. $query .= "position = {$position}, ";
  65. $query .= "visible = {$visible} ";
  66. # Comma removed here ----------^
  67. $query .= "WHERE id = {$id}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement