943,172 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 21
  • PHP RSS
Aug 31st, 2010
0

problem arise in reverse transactions

Expand Post »
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.
PHP Syntax (Toggle Plain Text)
  1. <style type="text/css">
  2. <!--
  3. #apDiv1 {
  4. position:absolute;
  5. width:27px;
  6. height:61px;
  7. z-index:1;
  8. left: 844px;
  9. top: 13px;
  10. }
  11. body {
  12. background-color:
  13. }
  14. -->
  15. </style>
  16. <table border='1'>
  17. <tr>
  18. <th>Account Number </th>
  19. <th><nbsp>Account Type</th>
  20. <th>Transaction Type </th>
  21. <th>Balance </th>
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. </tr>
  30.  
  31. <?php
  32. include 'transaction_view1.php';
  33. $vm= new employeeManager();
  34. $employees=$vm->getemployees();
  35. foreach($employees as $v)
  36. {
  37. ?>
  38. <tr>
  39. <td><?php echo $v[1];?></td>
  40. <td><?php echo $v[2];?></td>
  41. <td><?php echo $v[3];?></td>
  42. <td><?php echo $v[4];?></td>
  43. </td>
  44. </tr>
  45. <?php
  46. }
  47. ?>
  48. </table>
  49. <p>&nbsp;</p>
  50. <form name="form2" method="post" action="approve_transactions.php">
  51. <label>
  52. <input type="submit" name="button2" id="button2" value="Update">
  53. </label>
  54. </form>
  55. <p>&nbsp;</p>
  56. <form name="form1" method="post" action="delete_cash.php">
  57. <label>
  58. <input type="submit" name="button" id="button" value="Delete">
  59. </label>
  60. </form>
  61. <p>&nbsp;</p>
  62. <p>&nbsp;</p>
  63. <p>&nbsp;</p>

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include 'dbconnection.php';
  3. class employeeManager
  4. {
  5. public function getemployees()
  6. {
  7. $con=new DBConnect();
  8. $db=$con->getDB();
  9. $employee=array();
  10. $result=mysql_query('select * from transaction_table',$db);
  11. $count=0;
  12. while ($row = mysql_fetch_row($result))
  13. {
  14. $employee[$count]=$row;
  15.  
  16. $count++;
  17. }
  18. return $employee;
  19. }
  20.  
  21. public function get1employee($tran_ID)
  22. {
  23. $con=new DBConnect();
  24. $db=$con->getDB();
  25. $employee=array();
  26. $result=mysql_query("select * from transaction_table where tran_ID='$tran_ID'",$db);
  27.  
  28. while ($row = mysql_fetch_row($result))
  29. {
  30. $employee=$row;
  31.  
  32. $count++;
  33. }
  34. return $employee;
  35. }
  36. }
  37.  
  38.  
  39. ?>

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

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $connect=mysql_connect("localhost","root","");
  4. mysql_select_db("bank",$connect) or die ("could not select database");
  5.  
  6. //getting the faulty transaction
  7. $query = "SELECT * from transaction_table WHERE tran_ID=$_POST['tran_ID']";
  8. mysql_query($query) or die(mysql_error());
  9. $row=mysql_fetch_assoc($result);
  10.  
  11.  
  12. //Correcting the account type table
  13. if(strtolower($row['transaction_type'])=="deposit"){
  14. $operator = "-";
  15. }else{
  16. $operator = "+";
  17. }
  18. $query= "UPDATE `".$row['account_type']."` SET `balance`=(`balance`".$operator.$row['amount'].") WHERE `ID`='".$row['account_number']."'";
  19. mysql_query($query) or die(mysql_error());
  20.  
  21.  
  22. //deleting the faulty transaction
  23. $query = "DELETE from transaction_table WHERE tran_ID=$_POST['tran_ID']";
  24. mysql_query($query) or die(mysql_error());
  25.  
  26. ?>

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
PHP Syntax (Toggle Plain Text)
  1. $query = "SELECT * from transaction_table WHERE tran_ID=$_POST['tran_ID']";

Can anyone correct me?

Thanks,
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
heshanm is offline Offline
145 posts
since Aug 2010
Aug 31st, 2010
0
Re: problem arise in reverse transactions
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['tran_id'] and use that variable in the Select statement.
2. Force PHP to evaluate the array variable by enclosing it in braces:
PHP Syntax (Toggle Plain Text)
  1. $query = "SELECT * from transaction_table WHERE tran_ID={$_POST['tran_ID']}";
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Sep 15th, 2010
0
Re: problem arise in reverse transactions
Thanks a lot for your advises...
Reputation Points: 10
Solved Threads: 0
Junior Poster
heshanm is offline Offline
145 posts
since Aug 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How do I provide FTP Access to Customers on a Website ?
Next Thread in PHP Forum Timeline: regarding retrieving data and display in a form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC