Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('header.php');
- if(!isset($_SESSION))
- {
- session_start();
- }
- require_once("user.php");
- $user = new User();
- //Remember to give your form's submit tag a name ="submit " attribute
- if(isset($_POST['register'])){
- $user->customer=trim($_POST['c_name']);
- $user->email=trim($_POST['c_email']);
- $user->password=trim($_POST['c_pass']);
- $user->contact=trim($_POST['c_contact']);
- $user->address=trim($_POST['c_address']);
- $user->about=trim($_POST['about']);
- $user->gender=trim($_POST['gender']);
- $user->create();
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Register</title>
- <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
- <script type="text/javascript" src ="assets/js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <div class="col-md-9">
- <div class="box">
- <center>
- <h2>
- Register A new Account
- </h2>
- <p class="text-muted">
- If you any question please fell to contact us
- </p>
- </center>
- <form action="registration.php" method="post" >
- <div class="form-group">
- <label>
- Customer Name
- </label>
- <input type="text" class ="form-control" name="c_name" required>
- </div>
- <div class="form-group">
- <label>
- Customer Email
- </label>
- <input type="email" class ="form-control" name="c_email" required>
- </div>
- <div class="form-group">
- <label>
- Customer Password
- </label>
- <input type="password" class ="form-control" name="c_pass" required>
- </div>
- <div class="form-group">
- <label>
- Customer Contact
- </label>
- <input type="text" class ="form-control" name="c_contact" required>
- </div>
- <div class="form-group">
- <label>
- Customer Address
- </label>
- <input type="text" class ="form-control" name="c_address" required>
- </div>
- <div class="form-group" >
- <label>
- About you
- </label>
- <textarea class="form-control" name="about"></textarea>
- </div>
- <div class="form-group">
- <label >
- Gender:
- </label>
- <br/>
- <label class="radio" >
- <input type="radio" name="gender" value="male">Male
- </label>
- <label class="radio" >
- <input type="radio" name="gender" value="female">Female
- </label>
- </div>
- <div class="text-center">
- <button type="submit" name="register" class="btn btn-primary"><i class="fa fa-customer-md"></i>Register</button>
- </div>
- </form>
- </div>
- </div>
- </div>
- </body>
- </html>
- <?php
- //if it is going to need the database , then it's
- //probaly smart to require it before we start
- require_once('database.php');
- class User{
- public $customer='';
- public $email='';
- public $password='';
- public $contact='';
- public $address='';
- public $about='';
- public $gender='';
- public static function authenticate($username="",$password=""){
- global $database;
- $username =$database->escape_value($username);
- $password = $database->escape_value($password);
- $sql ="SELECT * FROM user WHERE email ='{$username}' AND password ='{$password}' LIMIT 1";
- $result_array = self::find_by_sql($sql);
- return !empty($result_array)? array_shift($result_array):false;
- }
- public static function find_by_sql($sql = ""){
- global $database;
- $result_set = $database->query($sql);
- $object_array = array();
- while($row = $database->fetch_array($result_set)){
- $object_array[] = self::instantiate($row);
- }
- return $object_array;
- }
- private static function instantiate($record){
- $object = new self;
- foreach ($record as $attribute => $value) {
- if($object->has_attribute($attribute)){
- $object->$attribute = $value;
- }
- }
- return $object;
- }
- private function has_attribute($attribute){
- //get_object_vars returns an associative array with all attributes
- //(incl.privae one) as the keys and their current values as the
- $object_vars = $this->attributes();
- //we dont care about the value,we just want to know if the key exists
- //will return true or false
- return array_key_exists($attribute, $object_vars);
- }
- protected function attributes(){
- //return an array of attribute names and theri values
- foreach (self::$db_fields as $field) {
- if(property_exists($this,$field)){
- $attributes[$field] =$this->$field;
- }
- }
- return $attributes;
- }
- public function create(){
- global $database;
- $sql = "INSERT INTO customer (customer,email,password,contact,address,about,gender) VAlUES('$customer','$email','$password','$contact','$address','$about','$gender')";
- echo $address .' fdg adfdfhfdkja';
- $database->query($sql);
- }
- }
- ?>
- <?php error_reporting(E_ALL);//display all the error of this page
- ?>
- <?php
- require_once("config/config.php");
- class MySQLDatabase{
- private $connection;
- public $last_query;
- private $magic_quotes_active;
- private $real_escape_string_exists;
- function __construct(){
- $this->open_connection();
- $this->magic_quotes_active = get_magic_quotes_gpc();
- $this->real_escape_string_exists = function_exists("mysql_real_escape_string");
- //i.e. PHP >=v4.3.0 or higher
- }
- function open_connection(){
- //CREATE A DATABASE CONNECTION
- $this->connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
- if(!$this->connection){
- die("database connecton failed ");
- }else {
- //Select the database
- $db_select = mysqli_select_db($this->connection,DB_NAME);
- if(!$db_select){
- die("Database selection failed: ".mysqli_error());
- }
- }
- }
- public function close_connection(){
- if(isset($this->connection)){
- mysqli_close($this->connection);
- unset($this->connection);
- }
- }
- public function query($sql){
- $this->last_query = $sql;
- $result = mysqli_query($this->connection,$sql);
- $this->confirm_query($result);
- return $result;
- }
- private function confirm_query($result){
- if(!$result)
- {
- $output = "Database query failed :" .mysqli_connect_error() . "<br>";
- $output .= "Last SQL query is: " . $this->last_query;
- die ($output);
- }
- }
- public function escape_value($value){
- if($this->real_escape_string_exists){
- //undo any magic quote effects so mysql_real_escape_string can do the work
- if($this->magic_quotes_active){
- $value = stripslashes($value);}
- $value = mysql_real_escape_string($value);
- }
- else {
- //magic quotes arent already on the add slashes manually
- if(!$this->magic_quotes_active){
- $value = addslashes($value);
- }
- //if magic quotes are active,then the slashes already exist
- }
- return $value;
- }
- public function fetch_array($result_set){
- return mysqli_fetch_array($result_set);
- }
- public function num_rows($result_set){
- return mysqli_num_rows($result_set);
- }
- public function insert_id(){
- //get the last id inserted over the current db connection
- return mysqli_insert_id($this->connection);
- }
- public function affected_rows(){
- return mysqli_affected_rows($this->connection);
- }
- }
- $database = new MySQLDatabase();
- ?>
Add Comment
Please, Sign In to add comment