Advertisement
Guest User

Untitled

a guest
May 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. //1. Database conecction
  3. $dbhost = "localhost";
  4. $dbuser = "josepojw_Trainer";
  5. $dbpass = "locker011";
  6. $dbname = "josepojw_Testing";
  7. $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  8.  
  9.  
  10. //Test is connection works
  11. if(mysqli_connect_errno()){
  12. die("connection failed" . mysqli_connect_error() . "(". mysqli_connect_errno() .")");
  13. }
  14. ?>
  15.  
  16. <?php
  17. //2. Perform query
  18.  
  19. // Hard coded to test
  20. $first = "first";
  21. $last = "last";
  22. $userid = "userid";
  23. $password = "password";
  24.  
  25. $query = "INSERT INTO login (first, last, userid, password)
  26. VALUES ('{$first}', '{$last}', '{$userid}', '{$password}')";
  27. //Most of the time these come from a form with post method
  28.  
  29. $result = mysqli_query($connection, $query);
  30.  
  31. if($result){
  32. echo "success";
  33. } else {
  34. die("failed");
  35. }
  36. ?>
  37.  
  38. <?php
  39. //3.Use returned data
  40. while($row = mysqli_fetch_row($result)){
  41. //get the first row and assign to the variable, loop increment
  42. var_dump($row);
  43. //output from each row
  44. echo "<hr />";
  45. //horizontal line tag
  46. }
  47. ?>
  48. <?php
  49. //4. Release the data
  50. mysqli_free_result($result);
  51. ?>
  52.  
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56. <title>database</title>
  57. </head>
  58. <body>
  59.  
  60. </body>
  61. </html>
  62.  
  63. <?php
  64. //5. Close the connection
  65. mysqli_close($connection);
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement