Jump to content

Archived

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

ibda12u

check for duplicate username in input form

Recommended Posts

I'm going crazy with some code I've got. I have a signup form, that asks for a username.
I'm trying to build and if else statement that won't insert data into the table if the username is already in the table.

This is my code.
[code]
if($AcceptTerms=="" || $UserPlan=="" ){$errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
} [b]if[/b]($errors==1){ echo $error;}
$link = mysql_connect("localhost","data","passwd");
mysql_select_db("data",$link);
$query2="SELECT Username FROM signup where Username='".$Username."'";
$result2=mysql_query($query2) or die(mysql_error());
$num_rows=mysql_num_rows($result2);
[b]if [/b]($num_rows == 1)
{ echo 'Username in use, hit back button please';
}[b]else[/b] {
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Username: ".$Username."NewPassword1: ".$NewPassword1."NewPassword2:".$NewPassword2."
AcceptTerms: ".$AcceptTerms."UserPlan: ".$UserPlan." ";
$link = mysql_connect("localhost","data","passwd");
mysql_select_db("data",$link);
$query="insert into signup(Username,NewPassword1,NewPassword2,AcceptTerms,UserPlan) values ('".$Username."','".$NewPassword1."','".$NewPassword2."','".$AcceptTerms."','".$UserPlan."')";
mysql_query($query);
?>
<?php
}
?>[/code]

The code pretty much ignores my code to check the db for the username, and goes ahead and inserts the duplicate username and info in the DB.

Any idea's?

Share this post


Link to post
Share on other sites
replace:

$query2="SELECT Username FROM signup where Username='".$Username."'";

with:

$query2="SELECT * FROM signup where Username='$Username'";

you pissed it up

Share this post


Link to post
Share on other sites
if ($AcceptTerms=="" || $UserPlan=="" ){
$errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1){
echo "$error";
}
$link = mysql_connect("localhost","data","passwd");
mysql_select_db("data",$link);
$query2="SELECT Username FROM signup where Username='".$Username."'";
$result2=mysql_query($query2) or die(mysql_error());
$num_rows=mysql_num_rows($result2);
if($num_rows == 1){
echo 'Username in use, hit back button please';
}else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Username: ".$Username."NewPassword1: ".$NewPassword1."NewPassword2:".$NewPassword2."
AcceptTerms: ".$AcceptTerms."UserPlan: ".$UserPlan." ";
$link = mysql_connect("localhost","data","passwd");
mysql_select_db("data",$link);
$query="insert into signup(Username,NewPassword1,NewPassword2,AcceptTerms,UserPlan) values ('".$Username."','".$NewPassword1."','".$NewPassword2."','".$AcceptTerms."','".$UserPlan."')";
mysql_query($query);
}
?>


ive neatened it up a bit, to be honest, this whole code is a mess. so much unneeded. add me on my msn - joe@joeyjoe.co.uk , dont email as i cannot recieve emails at this time.

Share this post


Link to post
Share on other sites
[!--quoteo(post=353451:date=Mar 9 2006, 06:14 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 9 2006, 06:14 PM) [snapback]353451[/snapback][/div][div class=\'quotemain\'][!--quotec--]
if ($AcceptTerms=="" || $UserPlan=="" ){
$errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1){
echo "$error";
}
$link = mysql_connect("localhost","data","passwd");
mysql_select_db("data",$link);
$query2="SELECT Username FROM signup where Username='".$Username."'";
$result2=mysql_query($query2) or die(mysql_error());
$num_rows=mysql_num_rows($result2);
if($num_rows == 1){
echo 'Username in use, hit back button please';
}else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Username: ".$Username."NewPassword1: ".$NewPassword1."NewPassword2:".$NewPassword2."
AcceptTerms: ".$AcceptTerms."UserPlan: ".$UserPlan." ";
$link = mysql_connect("localhost","data","passwd");
mysql_select_db("data",$link);
$query="insert into signup(Username,NewPassword1,NewPassword2,AcceptTerms,UserPlan) values ('".$Username."','".$NewPassword1."','".$NewPassword2."','".$AcceptTerms."','".$UserPlan."')";
mysql_query($query);
}
?>
ive neatened it up a bit, to be honest, this whole code is a mess. so much unneeded. add me on my msn - joe@joeyjoe.co.uk , dont email as i cannot recieve emails at this time.
[/quote]

Hmm... that still didn't resolve it. I added you as a buddy. msn - msanders@impact-x.com
It still just ignores the username I've inputted and adds it

Share this post


Link to post
Share on other sites

×

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.