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>&nbsp;</h2>
<h2>&nbsp;</h2>
<h2>Registration Form </h2>
<p>&nbsp;</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>&nbsp;</td>
						<td class="title02">&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					  </tr>
                                          
					  <tr height="30">
						<td width="10%">&nbsp;</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%">&nbsp;</td>
					  </tr>
					  <tr height="30">
						<td>&nbsp;</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%">&nbsp;</td>
					  </tr>
					  <tr height="30">
						<td>&nbsp;</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%">&nbsp;</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%">&nbsp;</td>
					  </tr>
                       <tr height="30">
						<td width="10%">&nbsp;</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%">&nbsp;</td> 
                        <tr height="30">
                        
						<td>&nbsp;</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>&nbsp;</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>&nbsp;</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();"/> 
                       &nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="reset" value="Reset" class="attribute1" />
					</p>
  </fieldset>
				</td>
				<td width="5%">&nbsp;</td>
			</tr>

			  <tr>

			    <td>&nbsp;</td>
			    <td>&nbsp;</td>
			    <td>&nbsp;</td>
  </tr>
			  
			  
			  
			  <tr>
			    <td>&nbsp;</td>
			    <td align="center">&nbsp;</td>
			    <td>&nbsp;</td>
  </tr>
			  <tr>
			    <td>&nbsp;</td>
                            <td><font color=red size="1" ></font></td>
			    <td>&nbsp;</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

Member Avatar for diafol
$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'
 
					)";
$r = mysql_query($insert_query);
Member Avatar for TechySafi

@ardav already solved your problem I think but one more thing you should do....

$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'
 
					)";
$r = mysql_query($insert_query);
if($r)
{
echo "<p> You are successfully registered. 
<p><a href=login_form.php>Click here</a> to login.";
}
//because until the processing is done successfully you don't know if registration is successful or not right?

Good luck :)

It works perfectly. Thanks for both of u guys.......:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.