ambo Posted February 18, 2009 Share Posted February 18, 2009 No matter what uaser name i use it comes up as it is already in use i just dont see the problem im sure it is plain as day but ive been looking at this screen for 7 hours HELP>?? if(strlen($username) < 5){ $readyForm = false; echo "Sorry, the username ".$_POST['uname']." is less than 5 characters."; echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } ; if(strlen($username) > 30){ $readyForm = false; die('Sorry, the username '.$_POST['uname'].' is less more than 30 characters.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } //if the name exists it gives an error if ($checkem != 0) { $readyForm = false; die('Sorry, the email '.$_POST['email'].' is already in use.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $checkusex = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($checkusex); //if the name exists it gives an error if ($check2 != 0) { $readyForm = false; die('Sorry, the username '.$_POST['username'].' is already in use.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } // this makes sure both passwords entered match if ($_POST['password1'] != $_POST['password2']) { $readyForm = false; die('Your passwords did not match. '); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } else if($readyForm = true) { Link to comment https://forums.phpfreaks.com/topic/145677-username-already-in-use-but-doesnt-exist/ Share on other sites More sharing options...
milesap Posted February 18, 2009 Share Posted February 18, 2009 Try if ($check2 > 0) { avoid using != 0 since anything exept 0 will return true on that if statement, including null. Print $check2 and what it's returning. Link to comment https://forums.phpfreaks.com/topic/145677-username-already-in-use-but-doesnt-exist/#findComment-764808 Share on other sites More sharing options...
niranjnn01 Posted February 18, 2009 Share Posted February 18, 2009 just a suggestion... output and check the value of $check2 in the following code. $check2 = mysql_num_rows($checkusex); Link to comment https://forums.phpfreaks.com/topic/145677-username-already-in-use-but-doesnt-exist/#findComment-764811 Share on other sites More sharing options...
ambo Posted February 18, 2009 Author Share Posted February 18, 2009 SRY Milesap I accidentaly put checkem in that was for the email the user section was towards the bottom of post // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $checkusex = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($checkusex); //if the name exists it gives an error if ($check2 != 0) { $readyForm = false; die('Sorry, the username '.$_POST['username'].' is already in use.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } Link to comment https://forums.phpfreaks.com/topic/145677-username-already-in-use-but-doesnt-exist/#findComment-764814 Share on other sites More sharing options...
ambo Posted February 18, 2009 Author Share Posted February 18, 2009 Ok wow now if the user name doesnt exist it will give the erro but submit the form anyway HMM... ill show you the whole process page incase its out of what i showed you <? include("dbconnect.php"); include("../include/mailer.php"); define("EMAIL_FROM_NAME", "Ryan"); define("EMAIL_FROM_ADDR", "[email protected]"); define("EMAIL_WELCOME", True); function sendWelcome($user, $email, $password1){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Welcome to Team Decura"; $body = $username.",\n\n" ."Welcome! You've just registered at The decura" ."with the following information:\n\n" ."Username: ".$username."\n" ."Password: ".$password."\n" ."If you ever lose or forget your password, a new " ."password will be generated for you and sent to this " ."email address, if you would like to change your " ."email address you can do so by going to the " ."My Account page after signing in.\n\n" ."-Staff"; } $mailer = new Mailer; function generateRandID(){ return md5($this->generateRandStr(16)); } /** * generateRandStr - Generates a string made up of randomized * letters (lower and upper case) and digits, the length * is a specified parameter. */ function generateRandStr($length){ $randstr = ""; for($i=0; $i<$length; $i++){ $randnum = mt_rand(0,61); if($randnum < 10){ $randstr .= chr($randnum+48); }else if($randnum < 36){ $randstr .= chr($randnum+55); }else{ $randstr .= chr($randnum+61); } } return $randstr; } ; //Post Variables $username = $_POST["uname"]; $password = $_POST["password1"]; $password2 = $_POST["password2"]; $email = $_POST["email"]; $fname = $_POST["fname"]; $lname = $_POST["lname"]; $state = $_POST["state"]; $steamid = $_POST["steamid"]; $ulevel = $_POST["ulvl"]; $uid = 0; $passmd5 = md5("$password"); // checks if the email is in use if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $emailcheck = $_POST['email']; $checkemex = mysql_query("SELECT email FROM users WHERE email = '$emailcheck'") or die(mysql_error()); $checkem = mysql_num_rows($checkemex); if(strlen($username) < 5){ $readyForm = false; echo "Sorry, the username ".$_POST['uname']." is less than 5 characters."; echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } ; if(strlen($username) > 30){ $readyForm = false; die('Sorry, the username '.$_POST['uname'].' is less more than 30 characters.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } //if the name exists it gives an error if ($checkem != 0) { $readyForm = false; echo('Sorry, the email '.$_POST['email'].' is already in use.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $checkusex = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($checkusex); //if the name exists it gives an error if ($check2 > 0) { $readyForm = false; echo('Sorry, the username '.$_POST['username'].' is already in use.'); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } // this makes sure both passwords entered match if ($_POST['password1'] != $_POST['password2']) { $readyForm = false; echo('Your passwords did not match. '); echo "<form action=\"../register.php\" method=\"post\" >" ."<input type=\"hidden\" name=\"uname\" value=\"$username\" />" ."<input type=\"hidden\" name=\"email\" value=\"$email\" />" ."<input type=\"hidden\" name=\"fname\" value=\"$fname\" />" ."<input type=\"hidden\" name=\"lname\" value=\"$lname\" />" ."<input type=\"hidden\" name=\"state\" value=\"$state\" />" ."<input type=\"hidden\" name=\"steamid\" value=\"$steamid\" />" ."<input type=\"submit\" value=\"Go Back\" /></form>"; } else if($readyForm = true) { //gets the current date... putenv("TZ=US/Eastern"); $time = time(); $sqluser = "INSERT INTO users (username,password,userid,userlevel,email,timestamp)". "VALUES ('{$username}', '{$passmd5}', '{$uid}', '{$ulevel}', '{$email}', '{$time}')"; MYSQL_QUERY($sqluser); $sqlinfo = "INSERT INTO userinfo (username,fname,lname,state,steamid) VALUES ('{$username}', '{$fname}', '{$lname}', '{$state}', '{$steamid}')"; MYSQL_QUERY($sqlinfo); $mailer->sendWelcome($username,$email,$password); echo("<meta http-equiv=\"refresh\" content=\"2;url=../index.php\"/><br />"); echo("$ulevel ".$_POST["ulvl"].""); } ?> Link to comment https://forums.phpfreaks.com/topic/145677-username-already-in-use-but-doesnt-exist/#findComment-764818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.