ambo Posted February 23, 2009 Share Posted February 23, 2009 This is my script that checks the form it worked fine and now even if there is an error it will submit anyway <?php include("dbconnect.php"); include("../include/mailer.php"); define("EMAIL_FROM_NAME", "Ryan"); define("EMAIL_FROM_ADDR", "Contact@thedecura.com"); 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"].""); } ?> Edit by thorpe; Added tags. Quote Link to comment https://forums.phpfreaks.com/topic/146590-solved-form-validation-problem/ Share on other sites More sharing options...
trq Posted February 23, 2009 Share Posted February 23, 2009 Your using the assignment operator when you should be using the comparison operator. Change this line.... else if($readyForm = true) { to.... else if($readyForm == true) { or even.... else if($readyForm) { Quote Link to comment https://forums.phpfreaks.com/topic/146590-solved-form-validation-problem/#findComment-769558 Share on other sites More sharing options...
ambo Posted February 23, 2009 Author Share Posted February 23, 2009 Now useing else if ($readyform == true) { even with no error it wont submitt the script now Quote Link to comment https://forums.phpfreaks.com/topic/146590-solved-form-validation-problem/#findComment-769565 Share on other sites More sharing options...
ambo Posted February 23, 2009 Author Share Posted February 23, 2009 Should i set ready form to true ?? at start then it will switch to false if error Quote Link to comment https://forums.phpfreaks.com/topic/146590-solved-form-validation-problem/#findComment-769566 Share on other sites More sharing options...
trq Posted February 23, 2009 Share Posted February 23, 2009 Should i set ready form to true ?? at start then it will switch to false if error Probably. I haven't really looked at your code, its hard to read and follow logically. Ive also noticed your using $this in this function.... function generateRandID(){ return md5($this->generateRandStr(16)); } its not part of any class so $this-> needs to be removed. Quote Link to comment https://forums.phpfreaks.com/topic/146590-solved-form-validation-problem/#findComment-769567 Share on other sites More sharing options...
ambo Posted February 23, 2009 Author Share Posted February 23, 2009 That solved it Here was the fix sry for taking up your time $readyform = true; if (error) { $readyform = fasle; } else if($readyForm = true) { Submit } Quote Link to comment https://forums.phpfreaks.com/topic/146590-solved-form-validation-problem/#findComment-769569 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.