Hi all,

The 2 tables are as follows.

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

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

In my accounts opening form there are 9 fields. NIC, Full name, Name with initials, Phone number, Address, Gender, DOB, Account Type, FD period

I want to insert data to these 2 tables in my database to proceed furthermore.The below code does not work..
Can anyone show me the error.The error message is,

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\MySite\php files\handlers\account.php on line 46

$query= "UPDATE account `".$_POST['account_type']."` , '"$_POST['fd_period']."' WHERE `account_number`='".$_POST['account_number']."'";
mysql_query($query) or die(mysql_error());


<form id="form1" name="form1" method="post" action="">
  <input type="submit" name="button" id="button" value="Home" />
<p>&nbsp;  </p>
//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 (
$query= "UPDATE account `".$_POST['account_type']."` , '"$_POST['fd_period']."' WHERE `account_number`='".$_POST['account_number']."'";
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();


Edited by heshanm: n/a

7 Years
Discussion Span
Last Post by heshanm
Featured Replies
  • 1

    [QUOTE]$query = "UPDATE account SET `account_type` = '$atype', `fd_period` = 'fdper' WHERE `account_number`= anum";[/QUOTE] Are you using this statement ? 'anum' should be '$anum'. Read More


Looking at the code I think the problem is you are not using the "SET" command to identify the variable you are updating. Normal syntax for an update statement is something like:

UPDATE table_name
set table_name.field5 = <field5data>,
table_name.field10 = <field10data>
where table_name.id = <record_id>

In your case I think the line should read:

$query= "UPDATE account 
set account_type =`".$_POST['account_type']."` , 
fd_period = '"$_POST['fd_period']."' 
WHERE `account_number`='".$_POST['account_number']."'";

Hopefully this will help but I am not sure about the $_POST. I think it should be the array (or hash) $info instead.


Thanks for your comments..

But still does not work..

An error message is like this..

) Notice: Undefined index: account_number in C:\wamp\www\MySite\php files\handlers\account.php on line 51
Call Stack
# Time Memory Function Location
1 0.0176 377192 {main}( ) ..\open_account.php:0
2 0.0303 392680 include_once( 'C:\wamp\www\MySite\php files\handlers\account.php' ) ..\open_account.php:44
Unknown column 'fd' in 'field list'

In my account table there is a field column called "fd_period". This should be activated only if the user selects "fd" as the account type in my form.

Is there a problem?


If I am reading the error correctly you do not have an index built on the account_number field.


Also clean your input. Use mysql_real_escape_string().

UPDATE account `".$_POST['account_type']."` , '"$_POST['fd_period']."' WHERE `account_number`='".$_POST['account_number']."'";

won't work, try:

$atype = mysql_real_escape_string($_POST['account_type']); //assuming this is a string
$fdper = mysql_real_escape_string($_POST['fd_period']); //assuming this is a string
$anum = intval($_POST['account_number']); //assuming this is an integer

$query = "UPDATE account SET `account_type` = '$atype', `fd_period` = 'fdper' WHERE `account_number`= anum";

Thanks a lot both of you.

But it seems the data has been going ONLY to the "account details" table. The account has been successfully opened.But the data does not go(update)into the "account" table..

Any ideas??

$query = "UPDATE account SET `account_type` = '$atype', `fd_period` = 'fdper' WHERE `account_number`= anum";
mysql_query($query) or die(mysql_error());

Are you saying this doesn't work?
Do you get any error messages?

Does this give a clue when you echo it out? e.g.

echo $query;

If it looks OK, copy and paste it into the phpMyAdmin (or MySQL GUI of your choice) query window to see if it raises an error.


The code works..

I am saying it does not update my account table. I also want to enter data to my "account" table.

account_type, fd_period does not update..


Are the fields numeric? We're passing strings, although I can't see that this should stop it. Pull the quotes around all numeric fields. Maybe?


$query = "UPDATE account SET `account_type` = '$atype', `fd_period` = 'fdper' WHERE `account_number`= anum";

Are you using this statement ? 'anum' should be '$anum'.

Votes + Comments
good spot

I have tried both of your codings. But still no luck...:-(

Is there a problem with my table structure?

I have used account_number as the primary key of both tables. I have also set account_number as AUTO INCREMENT in both the tables

account_details (account_number, nic,____)
account (account_number,____)


If all the data pertains to account, why have you go two tables anyway?


I want to store my account details in my "account" table and customer data in my "account_details" table.

It is difficult to store all the data in a single data. Then i want to use data in my "account" table to my cash transactions.


Even if you have two tables, you should have all data in only one of the two (so don't put something in both).


I have corrected it and now coding works. Thanks everyone who help me..:-)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.