/    Sign up×
Community /Pin to ProfileBookmark

help with validation existense of two or more fields

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

[code=php]<?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”);
}
?>[/code]

Thanks for attention in advance

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DexterMorganFeb 20.2011 — Are you trying to prevent duplicate username and email addresses?

If so, would this method be a solution?

[code=php] $qry = "SELECT * FROM members WHERE login='$login' OR email='$email"; [/code]
Copy linkTweet thisAlerts:
@azegurbauthorFeb 21.2011 — Thank you very much
×

Success!

Help @azegurb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...