Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(document).ready(function() {
- $("#submit").click(function() {
- var username = $("#username").val();
- var password = $("#password").val();
- var email = $("#email").val();
- var cpass = $("#cpass").val();
- //var dataString = 'name='+ name + '&email='+ email + '&phone='+ phone + '&company='+ company + '&subject='+ subject + '&message='+ message;
- var dataString = {
- username: $("#username").val(),
- password: $("#password").val(),
- email: $("#email").val(),
- cpass: $("#cpass").val()
- };
- $.ajax({
- type: "POST",
- url: "register-process.php",
- data: dataString,
- cache: true,
- success: function(html){
- $('.message').html("<?php $msg; ?>").fadeIn(500);
- }
- });
- return false;
- });
- });
- </script>
- <?php
- include'config/db.php';
- $msg = null;
- $date = date('Y-m-d H:i:s');
- $uname = (!empty($_POST['username']))?$_POST['username']:null;
- $pass = (!empty($_POST['password']))?$_POST['password']:null;
- $cpass = (!empty($_POST['cpass']))?$_POST['cpass']:null;
- $email = (!empty($_POST['email']))?$_POST['email']:null;
- if($_POST){
- $stmt = "SELECT COUNT(*) FROM members WHERE mem_uname = :uname";
- $stmt = $pdo->prepare($stmt);
- $stmt-> bindValue(':uname', $uname);
- $stmt-> execute();
- $checkunm = $stmt->fetchColumn();
- $stmt = "SELECT COUNT(*) FROM members WHERE mem_email = :email";
- $stmt = $pdo->prepare($stmt);
- $stmt->bindValue(':email', $email);
- $stmt->execute();
- $checkeml = $stmt->fetchColumn();
- if($uname == '' or $pass == '' or $cpass == '' or $email == ''){
- $msg = "<div class='message-error'>Fields cannot be left empty. Please fill up all the fields.</div>";
- }else if($checkunm > 0){
- $msg = "<div class='message-error'>This username is already registered. Please use a different username.</div>";
- }else if($checkeml > 0){
- $msg = "<div class='message-error'>This Email ID is already registered. Please use a different Email ID.</div>";
- }else if($pass != $cpass){
- $msg = "<div class='message-error'>Passwords are not matching.</div>";
- }else if(strlen($uname) > 12){
- $msg = "<div class='message-error'>Username should not be more than 12 characters long.</div>";
- }else if(strlen($uname) < 6){
- $msg = "<div class='message-error'>Username must be at least 6 characters long.</div>";
- }else if(strlen($pass) < 6){
- $msg = "<div class='message-error'>Password must be at least 6 characters long.</div>";
- }else{
- // If everything is ok, insert user into the database
- $stmt = "INSERT INTO members(mem_uname, mem_pass, mem_email)VALUES(:uname, :pass, :email)";
- $stmt = $pdo->prepare($stmt);
- $stmt-> bindValue(':uname', $uname);
- $stmt-> bindValue(':pass', password_hash($pass, PASSWORD_BCRYPT));
- $stmt-> bindValue(':email', $email);
- $stmt-> execute();
- if($meq){
- $msg = "<div class='message-success'>Congratulations! You have been registered successfully. You can now login!</div>";
- }else{
- $msg = "<div class='message-error'>Server Error! Please try again later. If problem persists, please contact support.</div>";
- }
- }
- }
- echo $msg;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement