Jump to content

Registration Help please


princeofpersia

Recommended Posts

Hi guys, I have this registration form, for some reasons it just gives me "please all fields" on registration, can u help me see where im wrong please? thanks in advance

 

code is attached below:

 


<?php

//php form registration starts here
if(isset($_POST['register'])){
$title=strip_tags($_POST ['title']);
$firstname=strip_tags($_POST['firstname']);
$surname=strip_tags($_POST['surname']);
$email=strip_tags($_POST ['email']);
$reemail=strip_tags($_POST ['reemail']);	
$password=strip_tags($_POST ['password']);	
$repassword=strip_tags($_POST ['repassword']);
$street=strip_tags($_POST ['street']);
$city=strip_tags($_POST ['city']);
$postcode=strip_tags($_POST ['postocde']);
$telephone=strip_tags($_POST ['telephone']);

if($title && $firstname && $surname && $email && $reemail && $password && $repassword && $street && $city && $postcode && $telephone)
{
$getemails=mysql_query("SELECT * FROM member WHERE email='$email'");
$row=mysql_fetch_assoc($getemails);
if(mysql_num_rows($getemails) > 0)
{
echo "This email is already registered in our database";
}
else {
if($email!=$reemail) echo "Your Emails do not match";
}



if($password!=$repassword) {

echo "Passwords do not match";
}

else {

$confirmedpass=md5($password);

$submitusers= mysql_query("INSERT INTO members (title,Firstname,Surname,Street,City,Postcode,EmailAddress,Password, TelephoneNo,Credit) VALUES 
('$title','$firstname','$surname','$street','$city','$postcode','$email','$confirmedpass','$telephone','0')");
}

}
else {echo "Please fill All required fields";}	
}









?>




Link to comment
Share on other sites

Just an update

 

I have even changed the code but still get the same thing,

 

if ($_POST['register']){

$title=strip_tags($_POST['title']);
$firstname=strip_tags($_POST['firstname']);
$surname=strip_tags($_POST['surname']);
$email=strip_tags($_POST['email']);
$reemail=strip_tags($_POST['reemail']);	
$password=strip_tags($_POST['password']);	
$repassword=strip_tags($_POST['repassword']);
$street=strip_tags($_POST['street']);
$city=strip_tags($_POST['city']);
$postcode=strip_tags($_POST['postocde']);
$telephone=strip_tags($_POST['telephone']);


if($firstname == "" || $surname == "" || $email == "" || $reemail == "" || $password == "" || $repassword == "" || $street == "" || $city == "" || $postcode == "" || $telephone == "")

echo "Please fill All required fields";

else 
{

$getemails=mysql_query("SELECT * FROM member WHERE email='$email'");
$row=mysql_fetch_assoc($getemails);
if(mysql_num_rows($getemails) > 0){
echo "This email is already registered in our database";

}
else 
{
if($email!=$reemail) echo "Your Emails do not match";
}

if($password!=$repassword) {

echo "Passwords do not match";
}

else {

$confirmedpass=md5($password);

$submitusers= mysql_query("INSERT INTO members (title,Firstname,Surname,Street,City,Postcode,EmailAddress,Password, TelephoneNo,Credit) VALUES 
('$title','$firstname','$surname','$street','$city','$postcode','$email','$confirmedpass','$telephone','0')");
}

}

}


?>

 

 

and this is my html, checked everyhting and still get the error

 

 

<!--Registration Form starts Here */ -->
<form name="register" action="" method="POST">



	<p><label for="title">Title</label>
	<select name="title">
		<option value="Mr">Mr</option>
		<option value="Miss">Miss</option>
		<option value="Mrs">Mrs</option>
		<option value="Others">Others</option>
	</select></p>


	<p><label for="firstname">First Name:</label><br /><input type="text" name="firstname"/></p>
	<p><label for="surname">Surname:</label><br /><input type="text" name="surname" /></p>
	<p><label for="email">Email:<label><br /><input type="text" name="email" /></p>
	<p><label for="reemail">Repeat Email:<label><br /><input type="text" name="reemail" /></p>
	<p><label for="password">Password:<label><br /><input type="password" name="password" /></p>
	<p><label for="repassword">Repeat Password:<label><br /><input type="password" name="repassword" /></p>
	<p><label for="street">Street:</label><br /><input type="text" name="street" /></p>
	<p><label for="city">City:</label><br /><input type="text" name="city" /></p>
	<p><label for="postcode">Postcode:</label><br /><input type="text" name="postcode" /></p>
	<p><label for="telephone">Telephone No:</label><br /><input type="text" name="telephone" /></p>

	<p><input type="submit" name="register" value="Register" /></p>



</form>

Link to comment
Share on other sites

Here is a rewrite of your code which fixes some other problems and adds better error handling. Let me know if you have any questions

<?php
    //Parse user input
    $title      = trim(strip_tags($_POST['title']));
    $firstname  = trim(strip_tags($_POST['firstname']));
    $surname    = trim(strip_tags($_POST['surname']));
    $email      = trim(strip_tags($_POST['email']));
    $reemail    = trim(strip_tags($_POST['reemail']));
    $password   = $_POST['password']; //Don't need to trim or remove tags
    $repassword = $_POST['repassword'];
    $street     = trim(strip_tags($_POST['street']));
    $city       = trim(strip_tags($_POST['city']));
    $postcode   = trim(strip_tags($_POST['postocde']));
    $telephone  = trim(strip_tags($_POST['telephone']));

    //Check for errors
    $errors = array();
    if(empty($firstname))  { $errors[] = "First name is required."; }
    if(empty($surname))    { $errors[] = "Surname is required."; }
    if(empty($email))      { $errors[] = "Email is required."; }
    if(empty($reemail))    { $errors[] = "Email confirmation is required."; }
    if(!empty($email) && !empty($reemail))
    {
        if($email!=$reemail)
        {
            $errors[] = "Your Emails do not match.";
        }
        else
        {
            $emailSQL = mysql_real_escape_string($email);
            $result = mysql_query("SELECT * FROM member WHERE email='$emailSQL'");
            if(mysql_num_rows($result))
            {
                $errors[] = "This email is already registered in our database";
            }
        }
    }
    if(empty($password))   { $errors[] = "Password is required."; }
    if(empty($repassword)) { $errors[] = "Password confirmation is required."; }
    if(!empty($password) && !empty($repassword) && $password!=$repassword)
    {
        $errors[] = "Your Passwords do not match.";
    }
    if(empty($street))     { $errors[] = "Street is required."; }
    if(empty($city))       { $errors[] = "City is required."; }
    if(empty($postcode))   { $errors[] = "Post code is required."; }
    if(empty($telephone))  { $errors[] = "Telephone is required."; }

    //Determine if errors occured
    if(count($errors)>0)
    {
        //There were errors - display them
        echo "The following errors occured:<br />\n";
        echo "<ul>\n";
        foreach($errors as $error)
        {
            echo "<li>{$error}</li>\n";
        }
        echo "</ul>\n";
    }
    else
    {
        //No errors occured - insert records
        $query = sprint_f("INSERT INTO members
                             (title, Firstname, Surname, Street ,City, Postcode,
                              EmailAddress, Password, TelephoneNo, Credit)
                           VALUES
                             ('%s', '%s', '%s', '%s', '%s',
                              '%s', '%s', '%s', '%s', '%d')",
                          mysql_real_escape_string($title),
                          mysql_real_escape_string($firstname),
                          mysql_real_escape_string($surname),
                          mysql_real_escape_string($street),
                          mysql_real_escape_string($city),
                          mysql_real_escape_string($postcode),
                          $emailSQL,
                          md5($password),
                          mysql_real_escape_string($telephone),
                         0);

        $submitusers= mysql_query($query);
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.