ibda12u Posted March 9, 2006 Share Posted March 9, 2006 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? Quote Link to comment Share on other sites More sharing options...
joecooper Posted March 9, 2006 Share Posted March 9, 2006 replace:$query2="SELECT Username FROM signup where Username='".$Username."'";with:$query2="SELECT * FROM signup where Username='$Username'";you pissed it up Quote Link to comment Share on other sites More sharing options...
ibda12u Posted March 9, 2006 Author Share Posted March 9, 2006 Same problem after that change :( Quote Link to comment Share on other sites More sharing options...
joecooper Posted March 10, 2006 Share Posted March 10, 2006 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 Link to comment Share on other sites More sharing options...
ibda12u Posted March 10, 2006 Author Share Posted March 10, 2006 [!--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.comIt still just ignores the username I've inputted and adds it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.