Jump to content

Problem in the coding of passing data into tables


heshan

Recommended Posts

Hi all,

 

I want to insert data to my "account_details" table and at the same time update it in my "account"table.

Here is the coding which ONLY passes data to my "account_details" table. But NOTHING will happen to my "account" table.

 

Can anyone help me out to find the error.... :(

 

The 2 tables look like this.

 

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

 

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

 

<?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'];
$account_type = $_POST['account_type'];
$fd_period = $_POST['fd_period'];

$insert_query = "INSERT INTO account_details (
                            nic,
		    full_name,
		    name_with_initials,
		    phone_number,
		    address,
		    gender,
		    date_of_birth
		    )
		    VALUES
		    (
                            '$nic',
		    '$full_name',
		    '$name_with_initials',
		    '$phone_number',
		    '$address',
		    '$gender',
		    '$date_of_birth'
		    )";
		   
					   
           	   
//Run a switch on the chosen type of account
if($_POST['account_type'] == "abhimani_plus") {
      if($_POST['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 number ".mysql_insert_id()." has been created successfully.";die();
}

$query = "UPDATE account SET 'account_type' = '$account_type', 'fd_period' = '$fd_period' WHERE 'account_number' = '$account_number'";

mysql_query($query) or die(mysql_error());


?>

You have single-quotes around your column names (three places), thereby making them strings instead of column names.

 

The WHERE clause is FALSE because you are testing if the string 'account_number' is the same as what is in the $account_number variable. Unless $account_number contained the string 'account_number', the WHERE clause is false and the query is not even being executed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.