I created a user login/registration system and the login works fine. But I can not seem to get the registration to insert the info into the database. It returns no errors and says the record is there but when you check from phpMyAdmin, the record is not there.
Here is the register.php page:
<?php
// starting a session
session_start();
// Checks if there is set a session
if (!isset($_SESSION['user']))
{
// if a session has not set, then don't give access
} else {
// if a session has been set, then give access.
echo "<meta http-equiv=\"refresh\" content=\"0;url=index2.php\" />";
}
?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
<?php include("includes/nav.php"); ?>
<?php include("includes/upper_content.php"); ?>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<div id="main_body">
<table width="936" align="center" cellpadding="10">
<tr>
<td align="center"><!-- ########## START MAIN CONTENT HERE ########## -->
<fieldset>
<legend>Create a Free Account</legend>
<form action="newreg.php" method="post" >
<p>Choose A Username:<br />
<span id="spry_first_name">
<input type="text" name="username" value="" size="36" /><br />
<span class="textfieldRequiredMsg">A value is required.</span>
</span>
</p>
<p>First Name:<br />
<span id="spry_first_name"><span id="sprytextfield7">
<input type="text" name="first_name" value="" size="36" />
<span class="textfieldRequiredMsg">A value is required.</span> <span class="textfieldMinCharsMsg">Minimum number of characters not met.(6)</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.(30)</span></span>
</p>
<p>Last Name:<br />
<span id="spry_last_name">
<input type="text" name="last_name" value="" size="36" /><br />
<span class="textfieldRequiredMsg">A value is required.</span>
</span>
</p>
<p>Email:<br />
<span id="spry_email">
<input type="text" name="email" value="" size="36" /><br />
<span class="textfieldRequiredMsg">A value is required.</span><br />
<span class="textfieldInvalidFormatMsg">Invalid format.</span>
</span>
</p>
<span id="spry_password">
<label>Password:<br />
<input type="password" name="password2" id="password" size="36" /><br />
</label>
<span class="passwordRequiredMsg">A value is required.</span><br />
<br />
<span class="passwordMinCharsMsg">Minimum number of characters not met. (6)</span><br />
<span class="passwordMaxCharsMsg">Exceeded maximum number of characters. (30)</span>
</span>
<p>Confirm Password:<br />
<span id="spry_password_confirm">
<input type="password" name="password3" value="" size="36" /><br />
<span class="confirmRequiredMsg">A value is required.</span><br />
<span class="confirmInvalidMsg">The values don't match.</span>
</span>
</p>
<p>Street Address:<br />
<span id="spry_street_address">
<input type="text" name="street_address" value="" size="36" /><br />
<span class="textfieldRequiredMsg">A value is required.</span></span></p>
<p>Apartment Number:<br />
<input type="text" name="apt_number" value="" size="36" />
</p>
<p>City:<br />
<span id="spry_city">
<input type="text" name="city" value="" size="36" /><br />
<span class="textfieldRequiredMsg">A value is required.</span></span></p>
<p>State:<br />
<span id="spry_state">
<select name="state" id="state">
<option selected="selected">Select...</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select><br />
<span class="selectRequiredMsg">Please select an item.</span></span></p>
<p>Zip Code:<br />
<span id="spry_zip_code">
<input type="text" name="zip_code" value="" size="36" maxlength="10" /><br />
<span class="textfieldRequiredMsg">A value is required.</span><br />
<span class="textfieldInvalidFormatMsg">Invalid format.</span></span></p>
<p>Date of Birth (Must be at least 18):<br />
<br />Format: MM/DD/YYYY<br />
<span id="spry_birthday">
<input type="text" name="birthday" value="" size="36" /><br />
<span class="textfieldRequiredMsg">A value is required.</span><br />
<span class="textfieldInvalidFormatMsg">Invalid format.</span></span></p>
<p>
<input type="submit" value="Submit Registration" />
</p>
</form>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("spry_first_name", "none", {validateOn:["blur"], minChars:6, maxChars:30});
var sprytextfield2 = new Spry.Widget.ValidationTextField("spry_last_name", "none", {validateOn:["blur"]});
var sprytextfield3 = new Spry.Widget.ValidationTextField("spry_email", "email", {validateOn:["blur"], hint:"username@server.tld"});
var sprypassword1 = new Spry.Widget.ValidationPassword("spry_password", {validateOn:["blur"], minChars:6, maxChars:30});
var spryconfirm1 = new Spry.Widget.ValidationConfirm("spry_password_confirm", "password", {validateOn:["blur"]});
var sprytextfield4 = new Spry.Widget.ValidationTextField("spry_street_address", "none", {validateOn:["blur"], hint:"Your home address."});
var sprytextfield5 = new Spry.Widget.ValidationTextField("spry_city", "none", {validateOn:["blur"], hint:"The city you live in."});
var spryselect1 = new Spry.Widget.ValidationSelect("spry_state", {validateOn:["blur"]});
var sprytextfield6 = new Spry.Widget.ValidationTextField("spry_zip_code", "zip_code", {validateOn:["blur"], hint:"Your 5 digit zip code."});
var sprytextfield8 = new Spry.Widget.ValidationTextField("spry_birthday", "custom", {validateOn:["blur"]});
//-->
</script>
</fieldset>
<!-- ########## END MAIN CONTENT HERE ########## --></td>
</tr>
</table>
<?php include("includes/footer.php"); ?>
<?php ob_flush(); ?>
<script type="text/javascript">
<!--
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "none", {validateOn:["blur"]});
//-->
</script>
Here is the newreg.php page:
<?php
require_once("includes/connection.php");
require_once("includes/functions.php");
$username = $_POST['username'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$birthday = $_POST['birthday'];
$street_address = $_POST['street_address'];
$apt_number = $_POST['apt_number'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip_code = $_POST['zip_code'];
$password = $_POST['password'];
$result = mysql_num_rows(mysql_query("SELECT * FROM iin_users WHERE username='$username'"));
if($result == 1)
{
echo "<center><h1>ERROR!</h1>The username you have chosen already exists!<br /><br /><a href=\"register.php\">Go Back</a></center>";
}
else
{
//Get MD5 hash of password
$password = md5($password);
mysql_query("INSERT INTO iin_users (username, first_name, last_name, email, birthday, street_address, apt_number, city, state, zip_code, password)
VALUES ( '$username', '$first_name, '$last_name', '$email', '$birthday', '$street_address', '$apt_number', '$city', '$state', '$zip_code', '$password')");
echo "<p>Congratulations! You have successfully registered!</p><p>Click <a href=\"login.php\">here</a> to login.</p>";
}
?>
Like I said, no errors unless the username is the one that is the default entry I made which is wickidgrafx. Then it tells me the username is taken. But if I use a different username, it says everything is ok and tells me to login.
Please help me. Thanks, Jason.