We help IT Professionals succeed at work.
Get Started

php validations

sanjay1911
sanjay1911 asked
on
269 Views
Last Modified: 2012-05-11
Hello, I am working on registration script. The validations that I have give are not working.
here is my code.
<?php 
// To load the config script, following command is used.
require_once('include/config.php');

// 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 ($num) $err .= "<br/>FAIL: USERNAME $uid IS ALREADY TAKEN.  PLEASE CHOOSE ANOTHER USERNAME";

    // 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"]))
        {
            remember_me($uuk);
        }

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

    // If there were errors, display the following error message
    else
    {
        echo $err;
        echo "<br/>SORRY, REGISTRATION FAILED";
    }
} // Display the registratin form
?>
<form method="post">
<h2>PLEASE REGISTER</h2><p>
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" />
</form>

Open in new window

Comment
Watch Question
Senior Web Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE