hi all,
i have registration script that registers user according their user ID. if there more than one user id it returns false and says that this user ID is taken. but if i submit different user ID and the same email address it accepts. how can i do that if both user id and email exists it says that the user id is taken and the email is taken. thanks for attention
here is script
<?php
//Start session
session_start();
include("config/connect.php");
$az=new funksiyalar('karyeram');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
//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
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$email = clean($_POST['email']);
$cpassword = clean($_POST['cpassword']);
//Input Validations
if($fname == '') {
$errmsg_arr[] = 'Name necessary';
$errflag = true;
}
if($lname == '') {
$errmsg_arr[] = 'Surname is required';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Login is required';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password is required';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'please repeat password';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Passwords dont match';
$errflag = true;
}
//Check for duplicate login ID
if($login != '') {
$qry = "SELECT * FROM members WHERE login='$login'";
$result = mysql_query($qry);
//$yeni=mysql_fetch_array($result);
//$yeni[]
if($result) {
if(mysql_num_rows($result) > 0) {
$errmsg_arr[] = 'This login is already taken';
$errflag = true;
}
@mysql_free_result($result);
}
else {
die("Query failed");
}
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: register-form.php");
exit();
}
//Create INSERT query
$qry = "INSERT INTO members(firstname, lastname, login, passwd, password, email) VALUES ('$fname','$lname','$login','".md5($_POST['password'])."','$password','$email')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: register-success.php");
exit();
}else {
die("Query failed");
}
?>
Thanks for attention in advance