troubleshooting Question

php validations

Avatar of sanjay1911
sanjay1911 asked on
2 Comments1 Solution271 ViewsLast Modified:
Hello, I am working on registration script. The validations that I have give are not working.
here is my code.
// To load the config script, following command is used.

// An $err variable is set assuming that there are no errors. 
//Errors that occur during the registration process are checked later
$err = NULL;

// $_POST array is checked to see if all the required infoamtion is present.
//if registration informaitn is not available, then registration form is displayed
if ( (!empty($_POST["uname"])) && (!empty($_POST["uid"])) && (!empty($_POST["pwd"])) && (!empty($_POST["vwd"])) && (!empty($_POST["umail"])))
    // Yes, the posted data is available. Escape it for use in query
	$uname = mysql_real_escape_string($_POST["uname"]);
    $uid = mysql_real_escape_string($_POST["uid"]);
    $pwd = mysql_real_escape_string($_POST["pwd"]);
    $vwd = mysql_real_escape_string($_POST["vwd"]);
	$umail = mysql_real_escape_string($_POST["umail"]);

	if ($_POST['submit'])
	$uname = $_POST['uname'];
	$uid = $_POST['uid'];
	$pwd = $_POST['pwd'];
	$vwd = $_POST['vwd'];
	$umail = $_POST['umail'];	
	$err = ""; //default value of error string
	if (!$uname) 
	 $err = $err."Name<br>";
	 if (!$uid) 
	 $err = $err."Username<br>";
	 if (!$pwd) 
	 $err = $err."Password<br>";
	 if (!$vwd) 
	 $err = $err."Verify Password<br>";
	  if (!$umail) 
	 $err = $err."E-mail<br>";
	 if ($err!="")
	echo "Please fill out the following fields:<br>$err";
			 if ($uname != 'a-z,A-Z') $err .= "<br/>FAIL: PLEASE ENTER A VALID NAME";	 	 

			// do the password and verify password match?
    if ($pwd != $vwd) $err .= "<br/>FAIL: CHOOSE AND VERIFY PASSWORDS DO NOT MATCH";	 

    // Does the UID already exists?
    $sql = "SELECT uid FROM userTable WHERE uid = '$uid' LIMIT 1";
    if (!$res= mysql_query($sql)) die( mysql_error() );
    $num = mysql_num_rows($res);

    // If no errors were found, make unique user key
    if (!$err)
        // Make the unique user key
        $uuk = md5($uid . $pwd . rand());
        $sql = "INSERT INTO userTable (uname, uid, pwd, uuk, umail) VALUES ('$uname','$uid', '$pwd', '$uuk', '$umail')";
        if (!$res = mysql_query($sql)) die( mysql_error() );

        // store the User-ID in session array
        $_SESSION["uid"] = $uid;

        // check if the "REMEMBER ME" checkbox is set or not?
        if (isset($_POST["rme"]))

        // If registration is sucessfull, redirect the user to login_main page
echo "<meta http-equiv='refresh' content='0;url=\"99home.php?page=login_main\"'>";

    // If there were errors, display the following error message
        echo $err;
        echo "<br/>SORRY, REGISTRATION FAILED";
} // Display the registratin form
<form method="post">
YOUR NAME:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="uname" />
<br/>CHOOSE USERNAME: <input type="text" name="uid" />
<br/>CHOOSE PASSWORD: <input name="pwd" type="password" />
<br/>VERIFY PASSWORD:&nbsp;&nbsp; <input name="vwd" type="password" />
<br/>YOUR E-MAIL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<input name="umail" /><p>
<br/><h4><input type="checkbox" name="rme" />KEEP ME LOGGED IN </h4>
<br/><input type="submit" name="submit" value="REGISTER" />

Open in new window

Jagadishwor Dulal
Senior Web Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros