Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class db{
- public $host = "localhost";
- public $user = "root";
- public $pass = "";
- public $db_name = "oop";
- public $link;
- public function __construct(){
- $this->connect();
- }
- private function connect(){
- $this->link = new mysqli($this->host,$this->user,$this->pass,$this->db_name);
- }
- public function insert($query){
- $result = $this->link->query($query);
- if($result){
- echo "<center><h2>Registration successful</h2></center>";
- }
- else{
- echo "<center><h2>Registration not successful</h2></center>";
- }
- }
- }
- ?>
- 2. form.php
- <!DOCTYPE html>
- <html>
- <head>
- <title> Registration Form</title>
- <style type="text/css">
- body{
- padding: 0;
- margin:0;
- background: silver;
- }
- #form{
- width:30%;
- height:400px;
- background: white;
- margin:0 auto;
- padding: 20px;
- border: 1px solid black;
- }
- input{
- width:200px;
- height: 30px;
- margin: 5px;
- display: block;
- }
- label{
- margin:5px;
- font-weight:bold;
- }
- </style>
- </head>
- <body>
- <div id = "form">
- <h2>Registration Form</h2>
- <form method="post" action ="form.php">
- <label>User Name</label>
- <input type = "text" name = "name" placeholder="Enter user name" required="required"></input>
- <label>User Email</label>
- <input type = "text" name = "email" placeholder="Enter user Email" required="required"></input>
- <label> User Password</label>
- <input type = "password" name = "pass" placeholder="Enter password" required ="required"></input>
- <input type = "submit" name = "signup" value = "Sign Up"></input>
- </form>
- </div>
- </body>
- </html>
- <?php
- include "process.php";
- $db = new db();
- if(isset($_POST['signup'])) {
- $user = $_POST['name'];
- $email = $_POST['email'];
- $pass = $_POST['pass'];
- $query = "INSERT INTO users(user_name,user_email,user_pass) VALUES('$user','$email','$pass')";
- $db->insert($query);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement