Hi all,
I have created a registration form and a login form. But it is not working. The data would not go into the database. Can anyone show me the error.
I have posted my pages and database structure.
registration_form.php
<hr />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:177px;
height:55px;
z-index:1;
left: 12px;
top: 171px;
}
-->
</style>
</head>
<body>
<h2><img src="../images/image 1.jpg" alt="" width="118" height="89" /> <img src="../images/logo-default.jpg" alt="" width="350" height="89" /> <img src="../images/image 2.jpg" alt="" width="100" height="89" /></h2>
<h2> </h2>
<h2> </h2>
<h2>Registration Form </h2>
<p> </p>
<form name="form1" method="post" action="register.php" >
<fieldset>
<legend class="cap">User details</legend>
<table width="75%" border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td> </td>
<td class="title02"> </td>
<td> </td>
<td> </td>
</tr>
<tr height="30">
<td width="10%"> </td>
<td width="25%" class="title02" align="left">First Name</td>
<td width="55%" class="attribute1" align="left"><label>
<input type="text" name="first_name" id="textfield" />
</label></td>
<td width="10%"> </td>
</tr>
<tr height="30">
<td> </td>
<td width="25%" class="title02" align="left">Last Name</td>
<td width="55%" class="attribute1" align="left"><label>
<input type="text" name="last_name" class="attribute1" />
</label></td>
<td width="10%"> </td>
</tr>
<tr height="30">
<td> </td>
<td class="title02" align="left">Email</td>
<td class="attribute1" align="left"><input type="text" name="email" class="attribute1" /></td>
</tr>
<tr height="30">
<td width="10%"> </td>
<td width="25%" class="title02" align="left">Phone Number</td>
<td width="55%" class="attribute1" align="left"><label>
<input type="text" name="phone_number" class="attribute1" />
</label></td>
<td width="10%"> </td>
</tr>
<tr height="30">
<td width="10%"> </td>
<td width="25%" class="title02" align="left">User Type</td>
<td width="55%" class="attribute1" align="left"><input type="text" name="user_type" class="attribute1" /></td>
<td width="10%"> </td>
<tr height="30">
<td> </td>
<td class="title02" align="left">Username</td>
<td class="attribute1" align="left"><input type="text" name="username" class="attribute1" /></td>
<tr height="30">
<td> </td>
<td class="title02" align="left">Password</td>
<td class="attribute1" align="left"><input type="password" name="password" class="attribute1" /></td>
</tr>
<tr height="30">
<td> </td>
<td class="title02" align="left">Confirm Password</td>
<td class="attribute1" align="left"><input type="password" name="confirm_password" class="attribute1" /></td>
</tr>
</table>
<p align="center">
<input type="submit" name="submit" value="Submit" class="attribute1" onClick="return Validate();"/>
<input type="reset" name="reset" value="Reset" class="attribute1" />
</p>
</fieldset>
</td>
<td width="5%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="center"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><font color=red size="1" ></font></td>
<td> </td>
</tr>
</table>
</form>
<script language = "Javascript">
function Validate()
{
if (document.form1.first_name.value == '')
{
alert('Please fill in your first name!');
return false;
}
if (document.form1.last_name.value == '')
{
alert('Please fill in your last name!');
return false;
}
if (document.form1.email.value == '')
{
alert('Please fill in your email address!');
return false;
}
if (document.form1.phone_number.value == '')
{
alert('Please fill in phone number!');
return false;
}
if (document.form1.user_type.value == '')
{
alert('Please fill in your user type!');
return false;
}
if (document.form1.username.value == '')
{
alert('Please fill in your desired username!');
return false;
}
if (document.form1.password.value == '')
{
alert('Please fill in your desired password!');
return false;
}
if (document.form1.confirm_password.value == '')
{
alert('Please fill in your password again for confirmation!');
return false;
}
if (document.form1.password.value !=
document.form1.confirm_password.value)
{
alert("The two passwords are not identical! "+
"Please enter the same password again for confirmation");
return false;
}
return true;
}
</script>
</body>
</html>
register.php
<p> You are successfully registered.
<p><a href="login_form.php">Click here</a> to login.
<?php
$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$phone_number=$_POST['phone_number'];
$user_type=$_POST['user_type'];
$username=$_POST['username'];
$password=$_POST['password'];
$password=md5($password);
$insert_query = "insert into users (
first_name,
last_name,
email,
phone_number,
user_type,
username,
password
)
values
(
'$first_name',
'$last_name',
'$email',
'$phone_number',
'$user_type',
'$username',
'$password'
)";
($insert_query);
?>
Database name - bank
Table - users
Fields - user_id (Auto increment)
first_name
last_name
email
phone_number
user_type
username
password