I've been writing the Registration form in PHP. After completion of the code, it runs perfectly without any error (it says,"refistration not successfull") but the user information is not getting stored in database that i created. Complete code are given below:
Process.php:
<?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>";
}
}
}
?>
form.php:
<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>
<?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);
}
?>
help sorting out this problem.