problem in my accounts opening form

Hi All,

I want to do following things in my project.

[ul][li]There is an Accounts opening form. I want to open an account for each customer. In my form there are some restrictions need to be done. If the user selects gender type as " Male" and Account Type as “Abhimani plus” then there should be an error message saying "You do not meet the critera required to open this account"[/li]
[li][/li][/ul]

[ul][li]If all the data has been filled successfully there should be a message appeared as " You are successfully created Account number 1".
[/li]
[li][/li][/ul]

The above requirements do not work in my php scripts. Can anyone help me out…

Customer table in my bank database

Customer ( account_number, nic, full_name, name_with_initials, phone_number, address, date_of_birth, account_type, fd_period)

open_account.php

[php]


Untitled Document

 

 

Accounts Opening Form

 

<?php if(isset($_POST['run'])){include_once "./handlers/account.php";} ?> Customer details
             <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>
       

 

     

                 

    

 
       <tr>


         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
       <tr>
         <td>&nbsp;</td>
         <td align="center">&nbsp;</td>
         <td>&nbsp;</td>
    [/php]

account.php

[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 switch($info['account_type']) { //Abhimani Plus Account - I have used this as the account a male can't open. case "abhimani_plus": //Check if female if($info['gender']=="female") { //Account Creation Here } //If not a female if($info['gender']!="female") { //Show error messages here echo "You do not meet the critera required to open this account."; } } $r = mysql_query($insert_query); if($r) { echo "A new account with number ".mysql_insert_id()." has been created successfully."; } ?>

[/php]

Hi ,

try this code. hope this will help you.

In open-account.php file you have not define method of post if you want to create an account using this form then you need to define method of form POST or GET. as you are using post variable in account.php you have to define method of form to POST. i have make some changes to your form.
open_account.php
[php]

Untitled Document

 

 

Accounts Opening Form

 

<?php if(isset($_POST['run'])){include_once "./handlers/account.php";} ?> Customer details
             <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>
       

 

     

                 

    

 
       <tr>


         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
       <tr>
         <td>&nbsp;</td>
         <td align="center">&nbsp;</td>
         <td>&nbsp;</td>
    [/php]

account.php
[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(); } ?>

[/php]

Still it does not work.

After I loaded the page open_account.php and click on submit button then same page reloads and nothing happened. The validations were also not working.

Ex : If the user does not enter the nic of the customer, it should display as “Please enter nic” etc.

Where is the error?

Hi Heshanm,

I suspect the way you call your array is causing the problem. String array keys should be enclosed in quotes. So this particular code
[php]
VALUES
(
‘$info[nic]’,
‘$info[full_name]’,
‘$info[name_with_initials]’,
‘$info[phone_number]’,
‘$info[address]’,
‘$info[gender]’,
‘$info[account_type]’,
‘$info[fd_period]’
)";
[/php]
Should be:
[php]
VALUES
(
‘$info[“nic”]’,
‘$info[“full_name”]’,
‘$info[“name_with_initials”]’,
‘$info[“phone_number”]’,
‘$info[“address”]’,
‘$info[“gender”]’,
‘$info[“account_type”]’,
‘$info[“fd_period”]’
)";
[/php]

Hope this helps…

Thanks codeguru. :slight_smile: .It was some other mistake and i found. The form name missing and one data field missing in the database.Now it’s ok

Sponsor our Newsletter | Privacy Policy | Terms of Service