0

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.

Yubraj Rai
  • 33
  • 1
  • 13
  • Do your db have password and does it prompt any errors? – MuthaFury Jun 20 '16 at 07:25
  • no, i don't have db password...and doesn't prompt any errors – Yubraj Rai Jun 20 '16 at 07:29
  • By runs perfectly do you mean you see "Registration successful" after the form submit? – Chris Stryczynski Jun 20 '16 at 07:50
  • not..it's not connecting to database ..it says,"registration not successful" – Yubraj Rai Jun 20 '16 at 07:55
  • if says `registration not successful` because you print that without checking any errors. Use [`mysqli::$connect_errno`](http://php.net/manual/de/mysqli.connect-errno.php) and [`mysqli::$connect_error`](http://php.net/manual/de/mysqli.connect-error.php) to check for errors after the connection and [`mysqli::$errno `](http://php.net/manual/de/mysqli.errno.php) and [`mysqli::$error `](http://php.net/manual/de/mysqli.error.php) to check for errors after a query. They will tell you exactly what's the problem. – Gerald Schneider Jun 20 '16 at 07:59

0 Answers0