Advertisement
Guest User

insert

a guest
Apr 1st, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>My PHP Insert</title>
  6. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  7. </head>
  8. <body>
  9.  
  10. <div class="container container-form">
  11. <div class="panel panel-primary">
  12. <div class="panel-body">
  13. <form class="form-horizontal" method="post" name="myForm" id="myForm" action="insert.php" >
  14. <div class="form-group">
  15. <label class="col-sm-6"> Username </label>
  16. <div class="col-sm-6">
  17. <input type="email" pattern="[^ @]*@[^ @]*" name="username" class="form-control" id="username" required>
  18. </div>
  19. </div>
  20. <div class="form-group">
  21. <label class="col-sm-6"> Password </label>
  22. <div class="col-sm-6">
  23. <input type="password" name="password" class="form-control" id="password" required>
  24. </div>
  25. </div>
  26. <div class="form-group">
  27. <div class="col-sm-6">
  28. <button type="submit" class="btn btn-success"> Save </button>
  29. <button type="reset" class="btn btn-danger"> Clear </button>
  30. </div>
  31. </div>
  32. </form>
  33. <?php
  34. if($_SERVER["REQUEST_METHOD"] == "POST"){
  35. require_once 'config.php';
  36. $username=$_POST['username'];
  37. $password=password_hash($_POST['password'], PASSWORD_DEFAULT);
  38. try{
  39. $sql = "INSERT INTO users (username,password ) VALUES (:username,:password)";
  40. $stmt = $pdo->prepare($sql);
  41. // Bind parameters to statement
  42. $stmt->bindParam(':username', $username, PDO::PARAM_STR);
  43. $stmt->bindParam(':password', $password, PDO::PARAM_STR);
  44. $stmt->execute();
  45.  
  46. echo "Records inserted successfully.<br>";
  47. } catch(PDOException $e){
  48. die("ERROR: Could not able to execute $sql. " . $e->getMessage());
  49. }
  50. }
  51. ?>
  52. </div>
  53. </div>
  54. </div>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement