HI all,

I have a small problem regarding my php project.

There is a page called open_account.php. It contains all customer data such as NIC, full_name, date of birth, gender etc. When a user fills all the fields in that form it redirects to another page called new_account.php.

There are various account types in the bank. (Ex: A,B,C) I want to do something like this. When a user selects account B it has to show an error message saying " A male person cannot open a B account". Because it only allows women to open B account.

At the same time when a particular user selects an account say A, a message should be appeared as "Account number 1 has been successfully created"

I want your suggestions regarding how can i do these thing? I have attached all the php files

Database structure

customer(account_number,nic, full_name, name_with_initials, phone_number, address, gender, date_of_birth)

open_account.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>

<script src="datetimepicker_css.js">
  </script>  



<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>Accounts Opening Form </h2>
<p>&nbsp;</p>
<form name="form1" method="post" action="account.php" >
	
    
 			  
  <fieldset>
  <legend class="cap">Customer 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">NIC</td>
						<td width="55%" class="attribute1" align="left"><label>
						  <input type="text" name="nic" id="textfield" />
						</label></td>
						<td width="10%">&nbsp;</td>
					  </tr>
					  <tr height="30">
						<td>&nbsp;</td>
                        <td width="25%" class="title02" align="left">Full name</td>
				        <td width="55%" class="attribute1" align="left"><label>
				  <input type="text" name="full_name" class="attribute1" />
				  </label></td>
						<td width="10%">&nbsp;</td>
					  </tr>
					  <tr height="30">
						<td>&nbsp;</td>
						<td class="title02" align="left">Name with initials</td>
						<td class="attribute1" align="left"><input type="text" name="name_with_initials" 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">Address</td>
						<td width="55%" class="attribute1" align="left"><label>
						  <textarea name="address" id="textarea" cols="45" rows="5"></textarea>
						</label></td>
						<td width="10%">&nbsp;</td> 
    <tr height="30">
                        
						<td>&nbsp;</td>
						<td class="title02" align="left">Gender</td>
						<td class="attribute1" align="left"><label>
						  <select name="gender" id="select">
						    <option>Male</option>
                            <option>Female</option>
						    <option selected="selected"></option>
					        </select>
						</label></td>
    <tr height="30">
						<td>&nbsp;</td>
						<td class="title02" align="left">Date of birth</td>
						<td class="attribute1" align="left"><input type="Text" id="demo3" name="date_of_birth" maxlength="25" size="25"/><img src="../images/cal.gif" onClick="javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>&nbsp;</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.nic.value == '') 
    {
        alert('Please fill in nic!');
        return false;
    }
	if (document.form1.full_name.value == '') 
    {
        alert('Please fill in full name!');
        return false;
    }
    if (document.form1.name_with_initials.value == '') 
    {
       alert('Please fill in name with initials!');
       return false;
    }
	if (document.form1.phone_number.value == '') 
    {
        alert('Please fill in phone number!');
        return false;
    }
	if (document.form1.address.value == '') 
    {
        alert('Please fill in address!');
        return false;
    }
    if (document.form1.gender.value == '') 
    {
        alert('Please fill in gender!');
        return false;
    }
    if (document.form1.date_of_birth.value == '') 
    {
       alert('Please fill in date_of_birth!');
      return false;
    }
   
    
    return true;
}
</script>

    		
</body>
</html>

account.php

<?php

$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);

$nic=$_POST['nic'];
$full_name=$_POST['full_name'];
$name_with_initials=$_POST['name_with_initials'];
$phone_number= $_POST['phone_number'];
$address=$_POST['address'];
$gender=$_POST['gender'];
$date_of_birth=$_POST['date_of_birth'];

   
$insert_query = 'insert into customer (
					nic,
					full_name,
					name_with_initials,
					phone_number,
					address,
					gender,					
					date_of_birth
					) 
					values
					(
					"' . $_POST['nic'] . '", 
					"' . $_POST['full_name'] . '",
					"' . $_POST['name_with_initials'] . '",
					"' . $_POST['phone_number'] . '",
					"' . $_POST['address'] . '",
					"' . $_POST['gender'] . '",
					"' . $_POST['date_of_birth'] . '"
					)';

$r = mysql_query($insert_query);
if($r)
{
echo "<p> You are successfully entered customer details
<p><a href=new_account.php>Click here</a> to open a new account.";
}
//because until the processing is done successfully you don't know if registration is successful or not right?

?>

new_account.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script LANGUAGE="JavaScript">
function fd_show(val){
if(val=="fd"){
   document.getElementById("fd_box").style.visibility = 'visible';
  }else{
   document.getElementById("fd_box").style.visibility = 'hidden';
  }
}
</script>

<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>




<style type="text/css">
<!--
body,td,th {
   font-size: 18px;
   font-weight: bold;
}
-->
</style>


<style type="text/css">
<!--
body,td,th {
   font-size: 18px;
   font-weight: bold;
}
-->
</style>

</head>
<body>
<p><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" /></p>
<form id="form1" name="form1" method="post" action="">
  <label>
    <input type="submit" name="button" id="button" value="Logout" />
  </label>
</form>
<p>&nbsp;</p>
<form action="new_account.php" method="post" name="form2" id="form2" onSubmit="return Validate();">
  <fieldset>
    <legend class="cap">Create an Account</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>&nbsp;</td>
        <td width="25%" class="title02" align="left">Account Type</td>
        <td width="55%" align="left" bgcolor="#FFFFFF" class="attribute1">
        <select name="account_type" onChange="fd_show(this.value)">
            <option selected="selected"></option>
            <option value="savings_investment">Savings Investment</option>
            <option value="shakthi" >Shakthi</option>
            <option value="surathal">Surathal</option>
            <option value="abhimani_plus">Abhimani Plus</option>
            <option value="yasasa">Yasasa Certificates</option>
            <option value="fd">Fixed Deposits</option>
          </select>&nbsp;</td>
     
      <tr height="30">
        <td colspan="4">
            <div id="fd_box" style="visibility: hidden;">
            <table width="100%" border="0" cellspacing="0" cellpadding="5" align="center">
            <tr height="30">
                    <td width="10%">&nbsp;</td>
                    <td width="25%" class="title02" align="left">FD balance</td>
                    <td width="55%" class="attribute1" align="left"><input type="text" name="balance" class="attribute1" /></td>
                    <td width="10%">&nbsp;</td>
            </tr>
            <tr height="30">
              <td width="10%">&nbsp;</td>
              <td width="25%" class="title02" align="left">FD period</td>
              <td width="55%" class="attribute1" align="left"><select name="period">
                 <option selected="selected"></option>
                  <option value="< 1">less than 1 year</option>
                  <option value="1-3 years" >1-3 years</option>
                  <option value="> 3">more than 3 years</option>
                  <option value="il">immediate loan</option>
                </select></td>
              <td width="10%">&nbsp;</td>
            </tr>
            </table>
            </div>
        </td>
      </tr>
    </table>
    <p align="center">&nbsp;</p>
    <p align="center">
      <input type="submit" onClick="return Validate();" name="submit" value="Submit" class="attribute1" />
      &nbsp;&nbsp;
      <input type="reset" name="reset" value="Reset" class="attribute1" />
      &nbsp;&nbsp;
      <label>
        <input type="submit" name="button2" id="button2" value="Help" />
      </label>
    </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>
<p>&nbsp;</p>

<script language = "Javascript">

function Validate()
{
   /* if (document.form2.account_number.value == '')
    {
        alert('Please enter the valid account number!');
        return false;
   }*/
   else if ( document.form2.account_type.selectedIndex == '' )
    {
        alert ( "Please select an account type!." );
        return false;
    }
   return true;
}
</script>

</body>
</html>

Recommended Answers

All 6 Replies

Well, before you execute your query (account.php line 14), you'll have to do some validation. If gender == male && type == B echo error, something like that.

I have changed my coding. Now there are 2 pages relating to that. But still it does not working. When clicks on the submit button, the same page reloads and do nothing. The data values do not go into the database. The validations also not working. Can anyone help me out......:-(

Here is my codings.

open_account.php

<!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>
<script src="datetimepicker_css.js">
  </script>  
<script LANGUAGE="JavaScript">
function fd_show(val){
if(val=="fd"){
   document.getElementById("fd_box").style.visibility = 'visible';
  }else{
   document.getElementById("fd_box").style.visibility = 'hidden';
  }
}
</script>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>  
<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>Accounts Opening Form </h2>
<p>&nbsp;</p>
<?php if(isset($_POST['run'])){include_once "./handlers/account.php";} ?>
<form action="open_account.php" method="post">
<input type="hidden" name="run" value="yes" />
  <fieldset>
  <legend class="cap">Customer 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">NIC</td>
                  <td width="55%" class="attribute1" align="left"><label>
                    <input type="text" name="nic" id="textfield" />
                  </label></td>
                  <td width="10%">&nbsp;</td>
                 </tr>
                 <tr height="30">
                  <td>&nbsp;</td>
                        <td width="25%" class="title02" align="left">Full name</td>
                    <td width="55%" class="attribute1" align="left"><label>
              <input type="text" name="full_name" class="attribute1" />
              </label></td>
                  <td width="10%">&nbsp;</td>
                 </tr>
                 <tr height="30">
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Name with initials</td>
                  <td class="attribute1" align="left"><input type="text" name="name_with_initials" 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">Address</td>
                  <td width="55%" class="attribute1" align="left"><label>
                    <textarea name="address" id="textarea" cols="45" rows="5"></textarea>
                  </label></td>
                  <td width="10%">&nbsp;</td> 
    <tr height="30">
                        
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Gender</td>
                  <td class="attribute1" align="left"><label>
                    <select name="gender" id="select">
                           <option selected="selected"></option>
                      <option value="male">Male</option>
                            <option value="female">Female</option>
                     </select>
                  </label></td>
    <tr height="30">
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Date of birth</td>
                  <td class="attribute1" align="left"><input type="Text" id="demo3" name="date_of_birth" maxlength="25" size="25"/><img src="../images/cal.gif" onClick="javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>&nbsp;</td>
    </tr>
     
      
      <tr height="30">
        <td>&nbsp;</td>
        <td width="25%" class="title02" align="left">Account Type</td>
        <td width="55%" align="left" bgcolor="#FFFFFF" class="attribute1">
        <select name="account_type" onChange="fd_show(this.value)">
            <option selected="selected"></option>
            <option value="savings_investment">Savings Investment</option>
            <option value="shakthi" >Shakthi</option>
            <option value="surathal">Surathal</option>
            <option value="abhimani_plus">Abhimani Plus</option>
            <option value="yasasa">Yasasa Certificates</option>
            <option value="fd">Fixed Deposits</option>
          </select>&nbsp;</td>
     
      <tr height="30">
        <td colspan="4">
            <div id="fd_box" style="visibility: hidden;">
            <table width="100%" border="0" cellspacing="0" cellpadding="5" align="center">
            <tr height="30">
                   
            </tr>
            <tr height="30">
              <td width="10%">&nbsp;</td>
              <td width="25%" class="title02" align="left">FD period</td>
              <td width="55%" class="attribute1" align="left"><select name="fd_period">
                 <option selected="selected"></option>
                  <option value="< 1">less than 1 year</option>
                  <option value="1-3 years" >1-3 years</option>
                  <option value="> 3">more than 3 years</option>
                  <option value="il">immediate loan</option>
                </select></td>
              <td width="10%">&nbsp;</td>
            </tr>
            </table>
            </td>
      </tr>
  </table>
    <p align="center">&nbsp;</p>
    <p align="center">
      <input type="submit" onClick="return Validate();" name="submit" value="Submit" class="attribute1" />
      &nbsp;&nbsp;
      <input type="reset" name="reset" value="Reset" class="attribute1" />
      &nbsp;&nbsp;
      <label>
        <input type="submit" name="button2" id="button2" value="Help" />
      </label>
    </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>
<p align="center">&nbsp;&nbsp;&nbsp;&nbsp;</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.nic.value == '') 
    {
        alert('Please fill in nic!');
        return false;
    }
   if (document.form1.full_name.value == '') 
    {
        alert('Please fill in full name!');
        return false;
    }
    if (document.form1.name_with_initials.value == '') 
    {
       alert('Please fill in name with initials!');
       return false;
    }
   if (document.form1.phone_number.value == '') 
    {
        alert('Please fill in phone number!');
        return false;
    }
   if (document.form1.address.value == '') 
    {
        alert('Please fill in address!');
        return false;
    }
    if (document.form1.gender.value == '') 
    {
        alert('Please fill in gender!');
        return false;
    }
    if (document.form1.date_of_birth.value == '') 
    {
       alert('Please fill in date_of_birth!');
      return false;
    }

	



if (document.form1.account_type.value == '') 
    {
       alert('Please fill in type of account!');
      return false;
    }

	



if (document.form1.fd_period.value == '') 
    {
       alert('Please fill in period of fd!');
      return false;
    }
   
    
    return true;
}
</script>


          
</body>
</html>

account.php

<?php
$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);
//Create Array
$info = array(
           'nic' => $_POST["nic"],
           'full_name' => $_POST["full_name"],
           'name_with_initials' => $_POST["name_with_initials"],
           'phone_number' => $_POST["phone_number"],
           'address' => $_POST["address"],
           'gender' => $_POST["gender"],
           'date_of_birth' => $_POST["date_of_birth"],
           'account_type' => $_POST["account_type"], 
            'fd_period' => $_POST["fd_period"]          
           );
 //Prepare the Insert Query
$insert_query = "INSERT INTO customer (
               nic,
               full_name,
               name_with_initials,
               phone_number,
               address,
               gender,               
               date_of_birth,
               account_type,
               fd_period
               ) 
               VALUES
               (
               '$info[nic]', 
               '$info[full_name]', 
               '$info[name_with_initials]', 
               '$info[phone_number]', 
               '$info[address]', 
               '$info[gender]', 
               '$info[account_type]', 
               '$info[fd_period]'
               )";
//Run a switch on the chosen type of account
if($info['account_type'] == "abhimani_plus") {
      if($info['gender']!="female") {
         //Show error messages here
         echo "You do not meet the critera required to open this account.";exit;
      }
   }
 //Account Creation Here
$r = mysql_query($insert_query);
if($r) {
 echo "A new account with number ".mysql_insert_id()." has been created successfully.";die();
}
?>
Member Avatar for diafol

Before I wade in, is this a school project?

If not, do you really want to be storing people's data like NIC (I assume this is some sort of national insurance number)?

Just asking

It is a project relating to bank. The account numbers are saved in the database. The NIC (National Identity Card ) number is the unique way of identifying their customers.

Member Avatar for diafol

OK, just be sure that your data is kept extremely secure. There may be BIG implications to storing this sort of data. Depends what it is and local legislation.

Thanks ardarv for your advise...Now the form is working well. I had missed some quotations in the form.

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.