Jump to content

user registration problem


jbunn222

Recommended Posts

i'm having a problem getting my form to check if user exists in database my problem is the part in red all the other parts work except the checking of the user please help if able.

 

 

<?php

session_start();

require("./test/includes/conn.php");

?>

 

<html>

<head>

<title>Create An Account</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>

<table>

<?php

if (isset($_POST['createaccount'])){

 

 

$email = "$_POST";

$pass = $_POST['password'];

$encryptpass = md5($pass);

 

$errors = '';

 

if (strlen($_POST['firstname']) <5)

{

$errors .= '<tr><td>Your first name must contain a minimum of 5 characters</td></tr>';

}

 

if (strlen($_POST['lastname']) <5)

{

$errors .= '<tr><td>Your last name must contain a minimum of 5 characters</td></tr>';

}

 

if (empty($_POST['dob']))

{

$errors .= '<tr><td>Your date of birth is required</td></tr>';

}

 

if (!preg_match('/^[a-zA-Z0-9&\'\.\-_\+]+@[a-zA-Z0-9\-]+\.([a-zA-Z0-9\-]+\.)*+[a-zA-Z]{2}/is', $email))

{

$errors .= '<tr><td>Your email address appears to be invalid</td></tr>';

}

 

if (empty($_POST['phone']))

{

$errors .= '<tr><td>Your phone number is required</td></tr>';

}

 

if (strlen($_POST['streetaddress']) <10)

{

$errors .= '<tr><td>Your street address must contain a minimum of 10 characters</td></tr>';

}

 

if (strlen($_POST['city']) <3)

{

$errors .= '<tr><td>Your city must contain a minimum of 3 characters</td></tr>';

}

 

if (empty($_POST['state']))

{

$errors .= '<tr><td>Please choose a state from the list</td></tr>';

}

 

if (strlen($_POST['zipcode']) < 5)

{

$errors .= '<tr><td>Your zip code must contain a minimum of 5 characters</td></tr>';

}

 

if (empty($_POST['country']))

{

$errors .= '<tr><td>Please choose a country from the list</td></tr>';

}

 

if (strlen($_POST['username']) <5)

{

$errors .= '<tr><td>Your user name must contain a minimum of 5 characters</td></tr>';

}

 

if (strlen($_POST['password']) < 5 or strlen($_POST['password']) >15)

{

$errors .= '<tr><td>Your password must contain a minimum of 5 characters and a maximum of 15 characters</td></tr>';

}

 

if ($_POST['password'] != $_POST['confirmpassword'])

{

$errors .= '<tr><td>Your password and confirm password fields did not match</td></tr>';

}

 

if ($errors == '')

{

 

$sql = "SELECT COUNT(*) FROM customers WHERE customers_username = '$_POST[username]'";

    $result = mysql_query($sql);

    if (!$result) {

        print "A database error ddd submission. If this error persists, please contact you@example.com.";

}

 

    if (mysql_result($result,0,0)>0) {

        print "A user already exists with your chosen username. Please try another.";

    }

 

 

else

{

    $sql = "INSERT INTO customers SET

              customers_username = '$_POST[username]',

              customers_password = '$encryptpass',

              customers_firstname = '$_POST[firstname]',

              customers_lastname = '$_POST[lastname]',

      customers_dob = '$yy-$mm-$dd',

      customers_email = '$_POST',

      customers_phone = '$_POST[phone]',

      customers_company = '$_POST[companyname]',

      customers_streetaddress = '$_POST[streetaddress]',

      customers_city = '$_POST[city]',

      customers_state = '$_POST[state]',

      customers_zipcode = '$_POST[zipcode]',

      customers_country = '$_POST[country]'";

    if (!mysql_query($sql))

        print "A database error occurred in processing your submission. If this error persists, please contact you@example.com.";

}

}

else

{

 

print "<b>Your form shows these errors:</b>";

print "<hr />";

print "$errors";

}

}

?>

</table>

 

<font color="red">NOTE:</font> If you already have an account with us, please use our <a href="login.php">login page</a>.

<br />

* indicates a required field.

 

<table>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

 

<b>Your Personal Information</b>

 

<tr>

<td colspan="2"><hr /></td>

</tr>

 

<tr>

<td align="left">First Name:</td>

<td><input type="text" name="firstname" value="<?php print $_POST["firstname"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align="left">Last Name:</td>

<td><input type="text" name="lastname" value="<?php print $_POST["lastname"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Date of Birth:</td>

<td><input type="text" name="dob" value="<?php print $_POST["dob"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Email Address:</td>

<td><input type="text" name="email" value="<?php print $_POST["email"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Phone Number:</td>

<td><input type="text" name="phone" value="<?php print $_POST["phone"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Company Name:</td>

<td><input type="text" name="companyname" value="<?php print $_POST["companyname"]; ?>"></td>

</tr>

 

<tr>

<td><b>Your Address</b></td>

</tr>

 

<tr>

<td colspan="2"><hr /></td>

</tr>

 

<tr>

<td align = "left">Street Address:</td>

<td><input type="text" name="streetaddress" value="<?php print $_POST["streetaddress"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">City:</td>

<td><input type="text" name="city" value="<?php print $_POST["city"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">State:</td>

<td><select name="state"><option value="" SELECTED>Please Select</option><option value="Alabama"<?php if($_POST['state']=='Alabama'){echo 'selected="selected"';}?>>Alabama</option><option value="Alaska"<?php if($_POST['state']=='Alaska'){echo 'selected="selected"';}?>>Alaska</option><option value="Arizone"<?php if($_POST['state']=='Arizona'){echo 'selected="selected"';}?>>Arizone</option><option value="Arkansas"<?php if($_POST['state']=='Arkansas'){echo 'selected="selected"';}?>>Arkansas</option><option value="California"<?php if($_POST['state']=='California'){echo 'selected="selected"';}?>>California</option><option value="Colorado"<?php if($_POST['state']=='Colorado'){echo 'selected="selected"';}?>>Colorado</option><option value="Connecticut"<?php if($_POST['state']=='Connecticut'){echo 'selected="selected"';}?>>Connecticut</option><option value="Delaware"<?php if($_POST['state']=='Delaware'){echo 'selected="selected"';}?>>Delaware</option><option value="DistrictofColumbia"<?php if($_POST['state']=='DistrictofColumbia'){echo 'selected="selected"';}?>>District of Columbia  </option><option value="Florida"<?php if($_POST['state']=='Florida'){echo 'selected="selected"';}?>>Florida</option><option value="Georgia"<?php if($_POST['state']=='Georgia'){echo 'selected="selected"';}?>>Georgia</option><option value="Hawaii"<?php if($_POST['state']=='Hawaii'){echo 'selected="selected"';}?>>Hawaii</option><option value="Idaho"<?php if($_POST['state']=='Idaho'){echo 'selected="selected"';}?>>Idaho</option><option value="Illinois"<?php if($_POST['state']=='Illinois'){echo 'selected="selected"';}?>>Illinois</option><option value="Indiana"<?php if($_POST['state']=='Indiana'){echo 'selected="selected"';}?>>Indiana</option><option value="Iowa"<?php if($_POST['state']=='Iowa'){echo 'selected="selected"';}?>>Iowa</option><option value="Kansas"<?php if($_POST['state']=='Kansas'){echo 'selected="selected"';}?>>Kansas</option><option value="Kentucky"<?php if($_POST['state']=='Kentucky'){echo 'selected="selected"';}?>>Kentucky</option><option value="Louisiana"<?php if($_POST['state']=='Louisiana'){echo 'selected="selected"';}?>>Louisiana</option><option value="Maine"<?php if($_POST['state']=='Maine'){echo 'selected="selected"';}?>>Maine</option><option value="Maryland"<?php if($_POST['state']=='Maryland'){echo 'selected="selected"';}?>>Maryland</option><option value="Massachusetts"<?php if($_POST['state']=='Massachusetts'){echo 'selected="selected"';}?>>Massachusetts</option><option value="Michigan"<?php if($_POST['state']=='Michigan'){echo 'selected="selected"';}?>>Michigan</option><option value="Minnesota"<?php if($_POST['state']=='Minnesota'){echo 'selected="selected"';}?>>Minnesota</option><option value="Mississippi"<?php if($_POST['state']=='Mississippi'){echo 'selected="selected"';}?>>Mississippi</option><option value="Missouri"<?php if($_POST['state']=='Missouri'){echo 'selected="selected"';}?>>Missouri</option><option value="Montana"<?php if($_POST['state']=='Montana'){echo 'selected="selected"';}?>>Montana</option><option value="Nebraska"<?php if($_POST['state']=='Nebraska'){echo 'selected="selected"';}?>>Nebraska</option><option value="Nevada"<?php if($_POST['state']=='Nevada'){echo 'selected="selected"';}?>>Nevada</option><option value="NewHampshire"<?php if($_POST['state']=='New Hampshire'){echo 'selected="selected"';}?>>New Hampshire</option><option value="NewJersey"<?php if($_POST['state']=='New Jersey'){echo 'selected="selected"';}?>>New Jersey</option></select> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Zip Code:</td>

<td><input type="text" name="zipcode" value="<?php print $_POST["zipcode"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Country:</td>

<td><select name="country"><option value="" SELECTED>Please Select</option><option value="USA"<?php if($_POST['country']=='USA'){echo 'selected="selected"';}?>>United States             </option></select> <font color="red">*</font></td>

</tr>

 

<tr>

<td><b>Your Login Details</b></td>

</tr>

 

<tr>

<td colspan="2"><hr /></td>

</tr>

 

<tr>

<td align = "left">Username:</td>

<td><input type="text" name="username" value="<?php print $_POST["username"]; ?>"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Password:</td>

<td><input type="password" name="password"> <font color="red">*</font></td>

</tr>

 

<tr>

<td align = "left">Confirm Password:</td>

<td><input type="password" name="confirmpassword"> <font color="red">*</font></td>

</tr>

 

<tr>

<td><input type="submit" name="createaccount" value="Create Account"></td>

</tr>

 

</form>

</table>

</body>

</html>

Link to comment
Share on other sites

oh and by the way when i click submit it shows my errors the first time around and keeps the original data entered, but when fixing the errors and clicking submit again the data goes away and it doesn't get entered into the database nor shows an error for an existing username in use

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.