Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("include/config.php");
- //Function to sanitize values received from the form. Prevents SQL injection
- function clean($str) {
- $str = @trim($str);
- if(get_magic_quotes_gpc()) {
- $str = stripslashes($str);
- }
- return mysql_real_escape_string($str);
- }
- //Sanitize the POST values
- $email = clean($_POST['email']);
- $username = clean($_POST['username']);
- $password = clean($_POST['password']);
- $cpassword = clean($_POST['cpassword']);
- //Input Validations
- if($email == '') {
- $errmsg_arr[] = 'Email missing';
- }
- if($login == '') {
- $errmsg_arr[] = 'Login ID missing';
- }
- if($password == '') {
- $errmsg_arr[] = 'Password missing';
- }
- if($cpassword == '') {
- $errmsg_arr[] = 'Confirm password missing';
- }
- if( strcmp($password, $cpassword) != 0 ) {
- $errmsg_arr[] = 'Passwords do not match';
- }
- //Check for duplicate login ID
- if($login != '') {
- $qry = "SELECT * FROM c4c_members WHERE username='$username'";
- $result = mysql_query($qry);
- if($result) {
- if(mysql_num_rows($result) > 0) {
- $errmsg_arr[] = 'Login ID already in use';
- }
- @mysql_free_result($result);
- }
- else {
- die("Query failed2");
- }
- }
- //If there are input validations, redirect back to the registration form
- if($errflag) {
- $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
- session_write_close();
- header("location: register.php");
- exit();
- }
- //Create INSERT query
- $qry = "INSERT INTO c4c_members(email, username, pass) VALUES('$email','$username','".md5($_POST['password'])."')";
- $result = @mysql_query($qry);
- //Check whether the query was successful or not
- if($result) {
- header("location: login.php");
- exit();
- }else {
- die("Query failed1");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement