Normal OOP Registration

1.Method Create

<?php

class Crud {

	public $conn;

	public function __construct() {
		$this->conn = mysqli_connect( "localhost", "root", "", "fresh" );
		if ( mysqli_connect() ) {
			//echo "Connect Successfully";
		} else {
			die( "connection error" );
		}
		session_start();
	}

	/* registration insert */

	public function regiInsert( $table, $firstname, $lastname, $username, $email, $password, $phone, $gender, $address ) {
		$query = mysqli_query( $this->conn, "INSERT INTO $table SET firstname='$firstname', lastname='$lastname', username='$username', email='$email', password='$password', phone='$phone', gender='$gender', address='$address' " );
		if ( mysqli_affected_rows( $this->conn ) > 0 ) {
			return true;
		} else {
			return false;
		}
	}


}

$obj = new Crud();

2.registration.php

<?php
include_once('../crud.php');
if (isset($_REQUEST['save'])) {
    //echo "<pre>";
    //print_r($_REQUEST);
    extract($_REQUEST);
    if ($obj->regiInsert("registration", $firstname, $lastname, $username, $email, sha1($password), $phone, $gender, $address)) {
        $err_msg = "Successfully You Registered, Please Sign in";
    } else {
        $err_msg = "Your registration not include";
    }
}
if(isset($_SESSION['username'])){
	header('location:home.php');
}
?>



<!doctype html>
<html>
    <head>
        <title>Registration Form</title>
        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"/>

        <!-- BootstrapValidator CSS -->
        <link rel="stylesheet" href="../bootstrap/css/bootstrapValidator.min.css"/>

        <!-- jQuery and Bootstrap JS -->
        <script type="text/javascript" src="../bootstrap/js/jquery-1.11.3.min.js"></script>
        <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>

        <!-- BootstrapValidator JS -->
        <script type="text/javascript" src="../bootstrap/js/bootstrapValidator.min.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div style="border: 1px solid #ddd; padding: 0 0 15px;" class="col-md-8 col-md-offset-2">
                    <div class="page-header">
                        <h2 style="text-align: center; font-family: initial;">Sign up</h2>
                        <p style="text-align:center; color: #4D73E4;">
                            <?php
                            echo isset($err_msg) ? $err_msg : "";
                            ?>
                        </p>
                    </div>

                    <form action="registration.php" id="registrationForm" method="post" class="form-horizontal">

                        <div class="form-group">
                            <label class="col-xs-3 control-label">Full name</label>
                            <div class="col-xs-4">
                                <input type="text" class="form-control" name="firstname" placeholder="First name" />
                            </div>
                            <div class="col-xs-4">
                                <input type="text" class="form-control" name="lastname" placeholder="Last name" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">Username</label>
                            <div class="col-sm-5">
                                <input type="text" class="form-control" name="username" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">Email address</label>
                            <div class="col-sm-5">
                                <input type="text" class="form-control" name="email" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">Password</label>
                            <div class="col-sm-5">
                                <input type="password" class="form-control" name="password" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-3 control-label">Phone number</label>
                            <div class="col-xs-5">
                                <input type="text" class="form-control" name="phone" placeholder="Phone Number" />
                            </div>
                        </div>	

                        <div class="form-group">
                            <label class="col-sm-3 control-label">Gender</label>
                            <div class="col-sm-5">
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="gender" value="male" /> Male
                                    </label>
                                </div>
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="gender" value="female" /> Female
                                    </label>
                                </div>
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="gender" value="other" /> Other
                                    </label>
                                </div>
                            </div>
                        </div>
                        <!-- 
                        <div class="form-group">
                             <label class="col-sm-3 control-label">Date of birth</label>
                             <div class="col-sm-5">
                                 <input type="date" class="form-control" name="date"  placeholder="YYYY/MM/DD" />
                             </div>
                         </div>-->

                        <div class="form-group">
                            <label class="col-sm-3 control-label">Address</label>
                            <div class="col-sm-5">
                                <textarea name="address" class="form-control" rows="5" cols="25"></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-9 col-sm-offset-3">
                                <!-- Do NOT use name="submit" or id="submit" for the Submit button -->
                                <button type="submit" name="save" value="submit" class="btn btn-default">Sign up</button>
                                <a class="btn btn-default" href="http://127.0.0.1/ibcs/fresh/template/admin/">Sign In</a>
                            </div>
                            
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <script>
            $(document).ready(function () {
                $('#registrationForm').bootstrapValidator({
                    // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        firstname: {
                            row: '.col-xs-4',
                            validators: {
                                notEmpty: {
                                    message: 'The first name is required'
                                }
                            }
                        },
                        lastname: {
                            row: '.col-xs-4',
                            validators: {
                                notEmpty: {
                                    message: 'The last name is required'
                                }
                            }
                        },
                        username: {
                            message: 'The username is not valid',
                            validators: {
                                notEmpty: {
                                    message: 'The username is required and cannot be empty'
                                },
                                stringLength: {
                                    min: 6,
                                    max: 30,
                                    message: 'The username must be more than 6 and less than 30 characters long'
                                },
                                regexp: {
                                    regexp: /^[a-zA-Z0-9]+$/,
                                    message: 'The username can only consist of alphabetical and number'
                                },
                                different: {
                                    field: 'password',
                                    message: 'The username and password cannot be the same as each other'
                                }
                            }
                        },
                        email: {
                            validators: {
                                notEmpty: {
                                    message: 'The email address is required and cannot be empty'
                                },
                                emailAddress: {
                                    message: 'The email address is not a valid'
                                }
                            }
                        },
                        password: {
                            validators: {
                                notEmpty: {
                                    message: 'The password is required and cannot be empty'
                                },
                                different: {
                                    field: 'username',
                                    message: 'The password cannot be the same as username'
                                },
                                stringLength: {
                                    min: 8,
                                    message: 'The password must have at least 8 characters'
                                }
                            }
                        },
                        phone: {
                            row: '.col-xs-5',
                            validators: {
                                notEmpty: {
                                    message: 'The cell phone number is required'
                                }
                            }
                        },
                        birthday: {
                            validators: {
                                notEmpty: {
                                    message: 'The date of birth is required'
                                },
                                date: {
                                    format: 'YYYY/MM/DD',
                                    message: 'The date of birth is not valid'
                                }
                            }
                        },
                        gender: {
                            validators: {
                                notEmpty: {
                                    message: 'The gender is required'
                                }
                            }
                        }
                        ,
                        address: {
                            validators: {
                                notEmpty: {
                                    message: 'Please input your valid address'
                                }
                            }
                        }
                    }
                });
            });
        </script>
    </body>
</html>

3.looking like this
registration

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s