Jump to content

registration script issue


Eggzorcist

Recommended Posts

I made a script in which registrates a user very basicly. here are the functions used.

 

I click submit get no error but it doesnt do anything to the databse nor does it send me the the url as indicated in the header();

 

 

<?php
require_once('config.php');

function secure_var($var){

$var = mysql_real_escape_string(htmlentities($var));

}

function check_username($username){

$query = mysql_query("SELECT * FROM user_info WHERE username = {$username}");

if ($query >= 1){

return true;

}

else {

return false; }

}


function check_email($email){

$query = mysql_query("SELECT * FROM user_info WHERE email = {$email}");

if ($query >= 1){

return true;

}

else {

return false; }


}


// Register User
function register_user($username, $password1, $password2, $email, $captcha){

secure_var($username);
secure_var($password1);
secure_var($password2);
secure_var($email);

$Error = null;

// Validate Username Field
if(!preg_match("/\A[a-z0-9_]{4,15}$/i",$username)){
	$Error .= "Username Can Only Contain Letters, Numbers and Underscores (Between 4-15 Characters Long) <br />";
}

// Validates Username Availability
if(check_username($username) == true){

$Error .= "You're chosen username is taken. Plase choose another one.<br />";

}

// Validates Email Availability
if (check_email($email) == true){

$Error .= "You're email is already in use.<br />";

} 

// Validate Password Field
if (!preg_match("/\A[a-z0-9 _-]{4,15}$/i",$password1)){
	$Error .= "Password Can Only Contain Letters, Numbers, And Underscores (Between 4-15 Characters Long <br />";
}

// Validate Password Confirmation
if ($password1 != $password2){
	$Error .= "Password and Password Confirmation Do Not Match <br />";
}

// Validate Email Address Format
if (!preg_match("/\A[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/", $email)){
	$Error .= "Email Address Must Be In format: [username]@[domain].[extension] <br />";
}

// Validate Security Image
if ($captcha != $_SESSION['captcha']){
	$Error .= "Your Captcha Input Does Not Match The Image Shown";
}		

// Result Success or Error
if($Error == null){


	$reg_user = mysql_query("INSERT INTO user_info (username, password, email) VALUES ($username, $password, $email)");

	if($reg_user){
	header('login.php?reg=1');
	}

}else{
	// Echo the error(s)
	echo($Error);
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/126740-registration-script-issue/
Share on other sites

The first things that I noticed were that you are checking to see if the query is greater than or equal to 1. mysql_query() returns a result resource. You need to perform mysql_num_rows() on the query then check if that is greater than or equal to 1, or just greater than 0.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.