Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2.  
  3. class db{
  4.  
  5. public $host = "localhost";
  6. public $user = "root";
  7. public $pass = "";
  8. public $db_name = "oop";
  9.  
  10. public $link;
  11.  
  12. public function __construct(){
  13. $this->connect();
  14. }
  15.  
  16. private function connect(){
  17. $this->link = new mysqli($this->host,$this->user,$this->pass,$this->db_name);
  18. }
  19.  
  20. public function insert($query){
  21. $result = $this->link->query($query);
  22.  
  23. if($result){
  24. echo "<center><h2>Registration successful</h2></center>";
  25. }
  26. else{
  27. echo "<center><h2>Registration not successful</h2></center>";
  28. }
  29. }
  30. }
  31.  
  32. ?>
  33. 2. form.php
  34. <!DOCTYPE html>
  35. <html>
  36. <head>
  37. <title> Registration Form</title>
  38. <style type="text/css">
  39. body{
  40. padding: 0;
  41. margin:0;
  42. background: silver;
  43. }
  44.  
  45. #form{
  46. width:30%;
  47. height:400px;
  48. background: white;
  49. margin:0 auto;
  50. padding: 20px;
  51. border: 1px solid black;
  52. }
  53.  
  54. input{
  55. width:200px;
  56. height: 30px;
  57. margin: 5px;
  58. display: block;
  59. }
  60. label{
  61. margin:5px;
  62. font-weight:bold;
  63. }
  64.  
  65.  
  66.  
  67. </style>
  68. </head>
  69. <body>
  70. <div id = "form">
  71. <h2>Registration Form</h2>
  72. <form method="post" action ="form.php">
  73. <label>User Name</label>
  74. <input type = "text" name = "name" placeholder="Enter user name" required="required"></input>
  75.  
  76. <label>User Email</label>
  77. <input type = "text" name = "email" placeholder="Enter user Email" required="required"></input>
  78.  
  79. <label> User Password</label>
  80. <input type = "password" name = "pass" placeholder="Enter password" required ="required"></input>
  81.  
  82. <input type = "submit" name = "signup" value = "Sign Up"></input>
  83. </form>
  84.  
  85. </div>
  86. </body>
  87. </html>
  88.  
  89. <?php
  90. include "process.php";
  91.  
  92. $db = new db();
  93.  
  94. if(isset($_POST['signup'])) {
  95.  
  96. $user = $_POST['name'];
  97. $email = $_POST['email'];
  98. $pass = $_POST['pass'];
  99.  
  100. $query = "INSERT INTO users(user_name,user_email,user_pass) VALUES('$user','$email','$pass')";
  101.  
  102. $db->insert($query);
  103. }
  104. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement