Hi guys,

In my projects i handle cash transactions. Whenever user enters transaction details it stored in the transaction_table. This is my 5 tables relevant to this.


transaction_table(tran_ID,account_number,account_type,transaction_type,amount)

savings_investment(ID,account_type,full_name,balance,interest,customer_id)

shakthi(ID,account_type,full_name,balance,interest,customer_id)

surathal(ID,account_type,full_name,balance,interest,customer_id)

abhimani_plus(ID,account_type,full_name,balance,interest,customer_id)

If the user enters wrong amount, the supervisor of my system wants to correct it immediately. so far i made following codings..

regarding retrieving data from transaction_table.

<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:27px;
	height:61px;
	z-index:1;
	left: 844px;
	top: 13px;
}
body {
	background-color: 
}
-->
</style>
<table border='1'>
  <tr>
<th>Account Number </th>
<th><nbsp>Account Type</th>
<th>Transaction Type </th>
<th>Balance </th>







</tr>

<?php
include 'transaction_view1.php';
$vm= new employeeManager();
$employees=$vm->getemployees();
foreach($employees as $v)
{
?>
<tr>
<td><?php echo $v[1];?></td>
<td><?php echo $v[2];?></td>
<td><?php echo $v[3];?></td>
<td><?php echo $v[4];?></td>
</td>
</tr>
<?php
}
?>
</table>
<p>&nbsp;</p>
<form name="form2" method="post" action="approve_transactions.php">
  <label>
    <input type="submit" name="button2" id="button2" value="Update">
  </label>
</form>
<p>&nbsp;</p>
<form name="form1" method="post" action="delete_cash.php">
  <label>
    <input type="submit" name="button" id="button" value="Delete">
  </label>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?php
include 'dbconnection.php';
class employeeManager
{
public function getemployees()
{
$con=new DBConnect();
$db=$con->getDB();
$employee=array();
$result=mysql_query('select * from transaction_table',$db);
$count=0;
while ($row = mysql_fetch_row($result))
{
$employee[$count]=$row;

$count++;
}
return $employee;
}

public function get1employee($tran_ID)
{
$con=new DBConnect();
$db=$con->getDB();
$employee=array();
$result=mysql_query("select * from transaction_table where tran_ID='$tran_ID'",$db);

while ($row = mysql_fetch_row($result))
{
$employee=$row;

$count++;
}
return $employee;
}
}


?>

Then in my reverse transaction page looks like this.
approve_transactions.php

<?php

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

//getting the faulty transaction
$query = "SELECT * from transaction_table WHERE tran_ID=$_POST['tran_ID']";
mysql_query($query) or die(mysql_error());
$row=mysql_fetch_assoc($result);


//Correcting the account type table
if(strtolower($row['transaction_type'])=="deposit"){
            $operator = "-";
      }else{
            $operator = "+";
      }
      $query= "UPDATE `".$row['account_type']."` SET `balance`=(`balance`".$operator.$row['amount'].") WHERE `ID`='".$row['account_number']."'";
      mysql_query($query) or die(mysql_error());
	  

//deleting the faulty transaction
$query = "DELETE from transaction_table WHERE tran_ID=$_POST['tran_ID']";
mysql_query($query) or die(mysql_error());

?>

But when i clicked on "Update" button following error occurred.

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\php files\approve_transactions.php on line 7

line 7

$query = "SELECT * from transaction_table WHERE tran_ID=$_POST['tran_ID']";

Can anyone correct me?

Thanks,

Recommended Answers

All 2 Replies

I suggest that you use an IDE (such as Netbeans) that will identify errors for you before you even try to execute the program.

PHP doesn't like this sort of array reference embedded the way you have done it. You have the same thing on line 23 as on line 7. There are a couple of ways that you can resolve it:

1. Set a variable equal to $_post and use that variable in the Select statement.
2. Force PHP to evaluate the array variable by enclosing it in braces:

$query = "SELECT * from transaction_table WHERE tran_ID={$_POST['tran_ID']}";

Thanks a lot for your advises...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.