Hi. I have created a registration form using two php files, sign.php and checkregister.php.
I am using a XAMPP server. The details are not going into the users table in the database ‘botho_collage’ when I browse it in PHPMyAdmin. I cannot see where I may have gone wrong.
sign.php
<div id="midPage">
<h1 align="center" class="Headings">PLEASE SIGN UP HERE</h1>
<form name="sign.php" action="checkregister.php" method="post">
<table align="center">
<tr>
<td>
Choose a User Name
</td>
<td>
<input type="text" size="30" name="username" title="Username">
</td>
</tr>
<tr>
<td>
Type In Your Email
</td>
<td>
<input type="text" size="30" name="email" title="Email">
</td>
</tr>
<tr>
<td>
Choose a Password
</td>
<td>
<input type="password" size="30" name="password">
</td>
</tr>
<tr>
<td>
Confirm Password
</td>
<td>
<input type="password" size="30" name="password2">
</td>
</tr>
<tr>
<td>
Gender
</td>
<td>
<select id="gender" onFocus="emptyElement('status')" width="20" name="gender">
<option value=""></option>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</td>
</tr>
<tr>
</tr>
</table>
<div align="center"><a href="#" onClick="return false" onMouseDown="openTerms()">
View Terms Of Use
</a>
</div>
<div id="terms" style="display:none;">
<h3 align="center">Botho Collage Terms</h3>
<p align="center">1. Use of this site is strictly for social/educational purposes for students enrolled within Botho University. </p>
<p align="center">2. Keep your password safe for security measures.</p>
<p align="center">3. Logging into another student's account is prohibited.</p>
<p align="center">4. Cyber bullying is not permitted.</p>
</div>
<p align="center">
<input type="submit" name="reg" value="Sign Up!">
</p>
</form>
</div>
checkregister.php
<?php
error_reporting(0);
//Posts the register from the form//
$reg = $_POST['reg'];
$uname = $_POST['username'];
$em = $_POST['email'];
$pswrd = $_POST['password'];
$pswrd2 =$_POST['password2'];
$gen = $_POST['gender'];
$d = date("Y-m-d"); // Shows year, month , day//
//Checks if all fields are filled//
if ($reg){
if ($uname&&$em&&$pswrd&&$pswrd2&&$gen)
{
//Checks if passwords are idenetical//
if ($pswrd==$pswrd2) {
// This checks if the username is at max length//
if (strlen($uname)>25) {
echo "Your password is too long!";
}
else
{
// This checks if the password is too long or too short//
if (strlen($pswrd)>25||strlen($pswrd)<5) {
echo "Your password is too short!";
}
else
{ //This encrypts the passwords//
$pswd = md5($pswrd);
$pswd2 = md5($pswrd2);
//Connects to the database//
$dbconnect = mysql_connect("localhost", "root", "hannu") or die ("Database Connection Failed");
mysql_select_db ("botho_collage",$dbconnect) or die ("Database Not Found");
$regquery= mysql_query("INSERT INTO users (id, username, email, password, gender, avatar, date) VALUES ('','$uname','$em','$pswrd','$gen','','$d')");
die ("You have been successfully registered! <a href='index.php'> You may now proceed to the login.</a>");
}
}
}
else
//Thses are the error messages for the user//
echo "Your passwords do not match!";
}
else
echo "Please fill in all of the fields!";
}
if (!mysql_query($regquery,$dbconnect))
{
die ('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($dbconnect);
?>