Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <?php
  2.  
  3. // 1. create a database connection
  4.  
  5. $dbhost = "localhost" ;
  6. $dbuser = "widget_cms";
  7. $dbpass = "secretpassword";
  8. $dbname = "widget_corp";
  9.  
  10. $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  11.  
  12. // test if connection occured
  13. if(mysqli_connect_errno())
  14. {
  15. die("database connection failed:". mysqli_connect_error() .
  16. " " . mysqli_connect_errno() . " " );
  17. }
  18.  
  19.  
  20. ?>
  21.  
  22. <?php
  23. //often these are $_POST values through a web form.
  24. // 2. Perform the database query
  25.  
  26. $id = 5;
  27. $menu_name = "delete me";
  28. $position = 4;
  29. $visible = 1;
  30.  
  31. $query = "UPDATE subjects SET ";
  32. $query .= "menu_name = '{ menu_name}', ";
  33. $query .= "position = {$position}, ";
  34. $query .= "visible = {$visible}, ";
  35. $query .= "WHERE id = {$id} ";
  36.  
  37. $result = mysqli_query($connection, $query);
  38.  
  39. if ($result)
  40. {
  41. //success
  42. //redirect to somepage.php
  43. echo "success!";
  44. }
  45. else
  46. {
  47. //failure
  48. //$message = "subjet update failed.";
  49. die("database query failed. " . mysqli_error($connection));
  50. }
  51. ?>
  52.  
  53. <DOCTYPE HTML>
  54. <head>
  55. <title> databases </title>
  56. </head>
  57.  
  58. <body>
  59.  
  60.  
  61.  
  62. </body>
  63.  
  64. </html>
  65.  
  66.  
  67. <?php
  68. // 5. close the database connection
  69. mysqli_close($connection);
  70. ?>
  71.  
  72. $query = "UPDATE subjects SET ";
  73. $query .= "menu_name = '{ menu_name}', ";
  74. $query .= "position = {$position}, ";
  75. $query .= "visible = {$visible} ";
  76. $query .= "WHERE id = {$id} ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement