Jump to content


Photo

check for duplicate username in input form


  • Please log in to reply
4 replies to this topic

#1 ibda12u

ibda12u
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 09 March 2006 - 08:27 PM

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.
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 
}
?>

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?


#2 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 09 March 2006 - 09:11 PM

replace:

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

with:

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

you pissed it up
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#3 ibda12u

ibda12u
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 09 March 2006 - 09:47 PM

Same problem after that change :(

#4 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 10 March 2006 - 12:14 AM

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.

Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#5 ibda12u

ibda12u
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 10 March 2006 - 03:25 PM

[!--quoteo(post=353451:date=Mar 9 2006, 06:14 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 9 2006, 06:14 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users