0

Hi all,

I want to perform cash transactions such as cash deposits and cash withdrawals in my project.Here i have created a page called transaction.php to fulfill those requirements.But there were few error which i need your help to sought it out..

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

transacion (tran_id, to_account_number, from_account_number, transaction_type, transaction_amount, transaction_date )

<?php

$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or die ("could not select database");

if(isset($_POST['submit'])){
$query= "SELECT `full_name` FROM account_details WHERE `account_number`='".$_POST['account_number']."'";
      $result = mysql_query($query) or die(mysql_error());
      $row = mysql_fetch_assoc($result);
      if(mysql_num_rows($result)==1 and $row['account_balance']<$_POST['transaction_amount'] and strtolower($_POST['transaction_type'])=="withdrawal"){
          echo "Insufficient balance";
      }elseif(mysql_num_rows($result)==1){

      if(strtolower($_POST['transaction_type'])=="deposit"){
$query = "INSERT INTO transaction (to_account_number) VALUES ('".$_POST['to_account_number']."')";
	  mysql_query($query) or die (mysql_error());
            $operator = "+";
      }else{
            $operator = "-";
$query = "INSERT INTO transaction (from_account_number) VALUES ('".$_POST['from_account_number']."')";
	  mysql_query($query) or die (mysql_error());		
      }
$query= "UPDATE account SET `account_balance`=(`account_balance`".$operator.$_POST['transaction_amount'].") WHERE `account_number`='".$_POST[               'account_number']."'";
mysql_query($query) or die(mysql_error());
   
$query = "INSERT INTO  transaction (transaction_type, transaction_amount, transaction_date) 
	            VALUES('".$_POST['transaction_type']."','".$_POST['transaction_amount']."','".$_POST['transaction_date']."')";
	  
mysql_query($query) or die(mysql_error());
            echo $row['full_name'].",<br> your transaction has been successfully processed";
      }else{
            echo "invalid account number";
      }
}
 
?>

Undefined index: account_balance in C:\wamp\www\MySite\php files\transactions.php on line 14

if(mysql_num_rows($result)==1 and $row['account_balance']<$_POST['transaction_amount'] and strtolower($_POST['transaction_type'])=="withdrawal"){

Undefined index: to_account_number in C:\wamp\www\MySite\php files\transactions.php on line 19

$query = "INSERT INTO transaction (to_account_number) VALUES ('".$_POST['to_account_number']."')";

Edited by heshanm: n/a

5
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by ko ko
0

the first error is due to this:-

$query= "SELECT `full_name` FROM account_details WHERE `account_number`='".$_POST['account_number']."'";

here you are only selecting the full name field only...and also check whether you want to select data from account or account_details

instead of this it should be

$query= "SELECT `full_name`,`account_number` FROM account_details WHERE `account_number`='".$_POST['account_number']."'";

And for ypur second error just check the spelling of variable in table or in the query.Just run the query in phpmyadmin and check whether it is working fine or not....

Edited by IIM: n/a

0

The same error again.

Here my account_balance comes from my "account" table.
full_name is from "account_details"table. How can i use it in the coding?

Regarding my second error,

I want to pass data to my "to_account_number" column when the user selects "deposit" as the transaction type.
I want to pass data to my "from_account_number" column when the user selects "withdrawal" as the transaction type.

0

@heshanm-For 1st error do this...
use join to read data from 2 tables ....For more information click here

0

heshanm - you've started about 5 threads on this issue now. Perhaps it would be an idea to keep to the same thread until the issue is finally resolved. All these different threads tend to rework covered ground. Just a thought.

0

@ ardav,

I thought, sometimes it is a mess for others to see all codings in a sigle thread when there were so many replies. That's why i thought to solve the issue step by step.Anyway your suggestion is welcomed.

@ IIM,

Thanks for the link.Do you have any ideas regarding my second issue? I was bit confused about that.

0

in the begining of your code, you check the post values and see whether you are getting expected variables, and their values or not

<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
$connect=mysql_connect("localhost","root","");
.
.
.

Edited by urtrivedi: n/a

0

I have changed the coding little bit and i found the error. It comes from this line.

}else if(mysql_num_rows($result)==1){

As a result it is ALWAYS give the output as "Invalid account number"

<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or die ("could not select database");

if(isset($_POST['submit'])){
$query = "SELECT account_details.full_name, account.account_balance ".
 "FROM account_details, account ".
	"WHERE account_details.account_number = account.account_number";
	
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
	  
if(mysql_num_rows($result)==1 and $row['account_balance']<$_POST['transaction_amount'] and strtolower($_POST['transaction_type'])=="withdrawal"){
          echo "Insufficient balance";
      }else if(mysql_num_rows($result)==1){

      if(strtolower($_POST['transaction_type'])=="deposit"){
	 
      $operator = "+";
      }else{
            $operator = "-";
	
	  }
$query= "UPDATE account SET `account_balance`=(`account_balance`".$operator.$_POST['transaction_amount'].") WHERE `account_number`='".$_POST['account_number']."'";
mysql_query($query) or die(mysql_error());
   
$query = "INSERT INTO  transaction (transaction_type, transaction_amount, transaction_date) 
	            VALUES('".$_POST['transaction_type']."','".$_POST['transaction_amount']."','".$_POST['transaction_date']."')";
	  
mysql_query($query) or die(mysql_error());

echo $row['full_name'].",<br> your transaction has been successfully processed";
}else{
       echo "invalid account number";
      }
}
 
?>
0

"SELECT account_details.full_name, account.account_balance ".
"FROM account_details, account ".
"WHERE account_details.account_number = account.account_number";

Check this query manually in phpMyAdmin. If 0 row returns, the problem is no account in table.

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.