Problem in passing data in a sigle form into 2 tables

Hi all,

I want to pass my form data in 2 tables. But this coding does ONLY passes data in my “account_details” table.Can anyone help me out regarding this problem. NOTHING will happen to my “account” table.

The 2 tables are as follows.

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

account (account_number, acccount_type, fd_period, account_balance, account_interest)

<form id="form1" name="form1" method="post" action="">
  <label>
  <input type="submit" name="button" id="button" value="Home" />
  </label>
</form>
<p>&nbsp;  </p>
<p>
  <?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 account_details (
               nic,
               full_name,
               name_with_initials,
               phone_number,
               address,
               gender,               
               date_of_birth
	 ) 
               VALUES
               (
               '$info[nic]', 
               '$info[full_name]', 
               '$info[name_with_initials]', 
               '$info[phone_number]', 
               '$info[address]', 
               '$info[gender]', 
               '$nfo[date_of_birth]'
			         
               )";
			   
$atype = mysql_real_escape_string($info['account_type']); //assuming this is a string
$fdper = mysql_real_escape_string($info['fd_period']); //assuming this is a string
$anum = intval($info['account_number']); //assuming this is an integer

$query = "UPDATE account SET `account_type` = '$atype', `fd_period` = '$fdper' WHERE `account_number`= '$anum'";
mysql_query($query) or die(mysql_error());
               	   
//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();
}

?>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

Something’s wrong with this line:
[php]
$anum = intval($info[‘account_number’]);
[/php]
“account_number” is not included in your $info array. So normally you’ll not be able to update your ‘account’ table.

Make sure $anum is not null and issue this query:
[php]
$query = “UPDATE account SET account_type = ‘$atype’, fd_period = ‘$fdper’ WHERE account_number = ‘$anum’”;
[/php]

I defined account_number in my $info array. But still it displayed "undefined index account_number as the error message

Thanks codeguru…

It was my mistake…now things are ok… :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service