Jump to content

Recommended Posts

@anyone

 

I have made a Bank transfer for but it work correctly as coded by it did not reflect in my sql database as expected.

 

it did not update my database

 

Hope someone could be of help..here is the code as stated below

------------------------------------------------------------------------------------------------------------------------------------------------

<?php
session_start();
include_once "config.php";
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
header("Location: login.php");
}else{
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username = '".$_SESSION['username']."'"));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>X-Bank : Bill Payment</title>
</head>

<body>
<table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
  <tr>
    <td width = "33%">You are logged as <?php echo "".$fetch_users_data->username."";?></div></td>
    <td width = "34%">Last IP Logged :</td>
    <td width = "33%">Your Account Balance is : $ <?php echo "".$fetch_users_data->acctbal."";?></div></td>
  </tr>
</table>
<br />
<table width = "100%" height = "294" border = "0" cellpadding = "1" cellspacing = "1">
  <tr valign = "top">
    <td width = "21%" height = "214"><table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
      <tr>
        <td><div align = "center"><a href = "members.php" >Home</a></div></td>
      </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "members.php">Members Profile</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "changepass.php">Change Password</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "billpayment.php">Bill Payment</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "fundtransfer.php">Fund Tranfser</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "loans.php">Loans</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "logout.php">Logout</a></div></td>
        </tr>
    </table></td>
    <td width = "79%" rowspan = "2">
      <table width = "80%" border = "1" align = "center" cellpadding = "1" cellspacing = "1">
        <tr>
          <td> <div align = "center">Pay bills online or transfer funds to any X-Bank Account Nationwide</div></td>
        </tr>
      </table>
      <br />
<?php
if(isset($_POST['bpayment']))
{
$reciversname = $_POST['reciversname'];
$amounttransact = $_POST['amounttransact'];
$anumber = $_POST['anumber'];
$bymemo = $_POST['bymemo'];
if($amounttransact == NULL OR $anumber == NULL )
{
$final_report .= "Your Payment was not initiated.";
}
else
{
$check_receiveraccct = mysql_query("SELECT * FROM members WHERE anumber = '".$_POST['anumber']."'");
if(mysql_num_rows($check_receiveraccct) != 0)
{
while ($row = mysql_fetch_array($check_receiveraccct))
{
$amounttransact = $row['amounttransact'];	
$anumber = $row['anumber'];
}
$acctbal = $intacctbal + $amounttransact;
if("UPDATE members SET intacctbal = '$intacctbal' WHERE anumber = '".$_POST['anumber']."'");
{
$check_senderaccct = mysql_query("SELECT * FROM members WHERE username = '".$_SESSION['username']."'");
while ($row = mysql_fetch_array($check_senderaccct))
{
$amounttransact = $row['amounttransact'];	
$anumber = $row['anumber'];	
}
$acctbal = $intacctbal - $amounttransact;
if("UPDATE members SET intacctbal = '$intacctbal' WHERE username = '".$_SESSION['username']."'");
{
$final_report .= "Your Transfer has been successful.";
}}}
else
{
$final_report .= "Receivers Account is invalid!.";
}}}
?>
<form method = "post">
        <table width = "64%" height = "133" border = "1" align = "center" cellpadding = "2" cellspacing = "1">
          <tr>
            <td width = "43%" height = "25">Receiver Name:</td>
            <td width = "57%"><div align = "center">
              <input name = "reciversname" type = "text" id = "reciversname" size = "35" maxlength = "50" />
            </div></td>
          </tr>
          <tr>
            <td height = "25">Amount:</td>
            <td width = "57%"><div align = "center">$ 
              <input name = "amounttransact" type = "text" id = "amounttransact" size = "33" maxlength = "30" />
            </div></td>
          </tr>
          <tr>
            <td height = "25">
              Receivers Account Number :</td>
            <td width = "57%"><div align  = "center">
              <input name = "anumber" type = "text" id = "anumber" size = "35" maxlength = "10" />
            </div></td>
          </tr>
          <tr>
            <td height = "25">Memo :</td>
            <td width = "57%"><div align = "center">
              <input name = "bymemo" type = "text" id = "bymemo" size = "35" maxlength = "30" />
            </div></td>
          </tr>
          <tr>
            <td height = "25" colspan = "2"><div align = "center">
              <input type = "submit" name = "bpayment" id = "bpayment" value = "Pay Bills" />
            </div></td>
          </tr>
        </table>
      </form>
      <table width = "80%" border = "1" align = "center" cellpadding = "1" cellspacing = "1" height = "30">
        <tr>
          <td><div align = "center"><?php echo "".$final_report.""; ?></div></td>
        </tr>
      </table>
      <p> </p>
    <p> </p></td>
  </tr>
  <tr valign="top">
    <td height="58"> </td>
  </tr>
</table>
<p> </p>
</body>
</html>

--------------------------------------------------------------------------------------------------------------------------------------------

any response or critic will be much appreciated for learning purpose..

 

 

Link to comment
https://forums.phpfreaks.com/topic/240659-fund-tranfer-form/
Share on other sites

1.  What happens if your script dies after adding money to the target account, but before taking money from the source account?

2.  When developing code you should check for errors like this:

 

$check_senderaccct = mysql_query("SELECT * FROM members WHERE username = '".$_SESSION['username']."'") or die("Error in query: " . mysql_error());

 

Even better if you can echo the query as well as the error message.

 

3.  What happens if two members transfer money to the same account at the same time?  The final balance could be incorrect.  To avoid problems here you should update balance like this:

 

$result = mysql_query(""UPDATE members SET intacctbal = intacctbal - $amounttransact WHERE username = '".$_SESSION['username']."'") or die("Error in query: " . mysql_error());

 

4.  Some of your queries are not inside mysql_query() - this is why they are not being executed.

Link to comment
https://forums.phpfreaks.com/topic/240659-fund-tranfer-form/#findComment-1236076
Share on other sites

I will be glad if someone can still tell me why my post cannot still update mysql after much help cos I have corrected the error based on

1.  What happens if your script dies after adding money to the target account, but before taking money from the source account?

2.  When developing code you should check for errors like this:

 

$check_senderaccct = mysql_query("SELECT * FROM members WHERE username = '".$_SESSION['username']."'") or die("Error in query: " . mysql_error());

 

Even better if you can echo the query as well as the error message.

 

3.  What happens if two members transfer money to the same account at the same time?  The final balance could be incorrect.  To avoid problems here you should update balance like this:

 

$result = mysql_query(""UPDATE members SET intacctbal = intacctbal - $amounttransact WHERE username = '".$_SESSION['username']."'") or die("Error in query: " . mysql_error());

 

4.  Some of your queries are not inside mysql_query() - this is why they are not being executed.

 

and please @Nightslyr, I am sorry once again for the mistake. so here is my modified code

 

<?php
session_start();
include_once "config.php";
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
header("Location: login.php");
}else{
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username = '".$_SESSION['username']."'")) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>X-Bank : Bill Payment</title>
</head>

<body>
<table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
  <tr>
    <td width = "33%">You are logged as <?php echo "".$fetch_users_data->username."";?></div></td>
    <td width = "34%">Last IP Logged :</td>
    <td width = "33%">Your Account Balance is : $ <?php echo "".$fetch_users_data->acctbal."";?></div></td>
  </tr>
</table>
<br />
<table width = "100%" height = "294" border = "0" cellpadding = "1" cellspacing = "1">
  <tr valign = "top">
    <td width = "21%" height = "214"><table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
      <tr>
        <td><div align = "center"><a href = "members.php" >Home</a></div></td>
      </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "members.php">Members Profile</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "changepass.php">Change Password</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "billpayment.php">Bill Payment</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "fundtransfer.php">Fund Tranfser</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "loans.php">Loans</a></div></td>
        </tr>
    </table>
      <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
        <tr>
          <td><div align = "center"><a href = "logout.php">Logout</a></div></td>
        </tr>
    </table></td>
    <td width = "79%" rowspan = "2">
      <table width = "80%" border = "1" align = "center" cellpadding = "1" cellspacing = "1">
        <tr>
          <td> <div align = "center">Pay bills online or transfer funds to any X-Bank Account Nationwide</div></td>
        </tr>
      </table>
      <br />
      <?php
if(isset($_POST['bpayment']))
{
$reciversname = $_POST['reciversname'];
$amounttransact = $_POST['amounttransact'];
$anumber = $_POST['anumber'];
$bymemo = $_POST['bymemo'];
if($amounttransact == NULL OR $anumber == NULL )
{
$final_report .= "Your Payment was not initiated.";
}
else
{
$check_receiveraccct = mysql_query("SELECT * FROM members WHERE anumber = '".$_POST['anumber']."'") or die(mysql_error());
if(mysql_num_rows($check_receiveraccct) != 0)
{
while ($row = mysql_fetch_array($check_receiveraccct))
{
$amounttransact = $row['amounttransact'];
$anumber = $row['anumber'];	
}
$acctbal = $intacctbal + $amounttransact;
$result_receiver = mysql_query("UPDATE members SET acctbal = $intacctbal + $amounttransact WHERE anumber = '".$_POST['anumber']."'") or die(mysql_error());
$check_senderaccct = mysql_query("SELECT * FROM members WHERE username = '".$_SESSION['username']."'") or die(mysql_error());
while ($row = mysql_fetch_array($check_senderaccct))
{
$amounttransact = $row['amounttransact'];
$anumber = $row['anumber'];
}
$acctbal = $intacctbal - $amounttransact;
$result_sender = mysql_query("UPDATE members SET acctbal = $intacctbal - $amounttransact WHERE anumber = '".$_SESSION['username']."'") or die(mysql_error());

$final_report .= "Your Transfer has been successful.";


}}}
?>
<form method = "post">
        <table width = "64%" height = "133" border = "1" align = "center" cellpadding = "2" cellspacing = "1">
          <tr>
            <td width = "43%" height = "25">Receiver Name:</td>
            <td width = "57%"><div align = "center">
              <input name = "reciversname" type = "text" id = "reciversname" size = "35" maxlength = "50" />
            </div></td>
          </tr>
          <tr>
            <td height = "25">Amount:</td>
            <td width = "57%"><div align = "center">$ 
              <input name = "amounttransact" type = "text" id = "amounttransact" size = "33" maxlength = "30" />
            </div></td>
          </tr>
          <tr>
            <td height = "25">
              Receivers Account Number :</td>
            <td width = "57%"><div align  = "center">
              <input name = "anumber" type = "text" id = "anumber" size = "35" maxlength = "10" />
            </div></td>
          </tr>
          <tr>
            <td height = "25">Memo :</td>
            <td width = "57%"><div align = "center">
              <input name = "bymemo" type = "text" id = "bymemo" size = "35" maxlength = "30" />
            </div></td>
          </tr>
          <tr>
            <td height = "25" colspan = "2"><div align = "center">
              <input type = "submit" name = "bpayment" id = "bpayment" value = "Pay Bills" />
            </div></td>
          </tr>
        </table>
      </form>
      <table width = "80%" border = "1" align = "center" cellpadding = "1" cellspacing = "1" height = "30">
        <tr>
          <td><div align = "center"><?php echo "".$final_report.""; ?></div></td>
        </tr>
      </table>
      <p> </p>
    <p> </p></td>
  </tr>
  <tr valign="top">
    <td height="58"> </td>
  </tr>
</table>
<p> </p>
</body>
</html>

 

I hope I got it the format of the message dis time cos I do not want to be flamed...

 

 

Link to comment
https://forums.phpfreaks.com/topic/240659-fund-tranfer-form/#findComment-1236282
Share on other sites

Thanks, that's the right format this time.

 

Carlito, can you please do the following:

 

1.  Indent your code like this:

 

if(mysql_num_rows($check_receiveraccct) != 0)
{
  while ($row = mysql_fetch_array($check_receiveraccct))
  {
    $amounttransact = $row['amounttransact'];
    $anumber = $row['anumber'];	
  }

 

Every time there is a "{", move the code to the right.  And back to the left when you reach the "}".  That will help me understand your code.

 

2.  Can you tell me what message you see?  And does any balance change?  Does it say "Your transfer has been successful.", but both source and destination balance have not changed?

Link to comment
https://forums.phpfreaks.com/topic/240659-fund-tranfer-form/#findComment-1236632
Share on other sites

Project: it the last amount transferred was 49.50. and I am transferring like $300

 

error : it will deduct 49.50 from the account balance instead of the regular $300 if $300 was the $amounttransact in the database. and when I check the receivers account, it will wipe the account balance and record the received amount as the new account balance.

guess they are many bugs..but still trying 2 sort them out

<?php
   if(isset($_POST['bpayment']))
      {
         $reciversname = $_POST['reciversname'];
         $amounttransact = $_POST['amounttransact'];
         $anumber = $_POST['anumber'];
         $bymemo = $_POST['bymemo'];
            if($reciversname == NULL OR $amounttransact == NULL OR $anumber == NULL )
               {
                  $final_report .= "Your Payment was not initiated.";
               }
            else
               {
                  $check_receiveraccct = mysql_query("SELECT * FROM members WHERE anumber = '".$_POST[       
		      'anumber']."'") or die(mysql_error());
                     while ($row = mysql_fetch_array($check_receiveraccct))
                     {
                        $amounttransact = $row['amounttransact'];
                        $anumber = $row['anumber'];	
                        $acctbal = $row['acctbal'];
                        $statementdate = $row['$statementdate'];
                        $transctype = $row['transctype'];
                     }
                        if(mysql_num_rows($check_receiveraccct) != 0)
                           {
                              $charges = '0.00';
                              $transctype = 'Bill Payment';
                              $acctbal = $intacctbal + $amounttransact;
                              $result_receiver = mysql_query("UPDATE members SET acctbal = '$acctbal +                              $amounttransact' , amounttransact = '$amounttransact' , statementdate =    
					      '$statementdate', transctype = '$transctype', charges = '$charges' WHERE 
					      anumber = '$_POST[anumber]'") or die(mysql_error());
						  $check_senderaccct = mysql_query("SELECT * FROM members WHERE username = '".   
						  $_SESSION['username']."'") or die(mysql_error());
                                 while ($row = mysql_fetch_array($check_senderaccct))
                                 {
                                    $amounttransact = $row['amounttransact'];
                                    $anumber = $row['anumber'];	
                                    $acctbal = $row['acctbal'];
                                    $statementdate = $row['statementdate'];
                                    $statementtrasct = $row['statementtrasct'];
                                    $charges = $row['charges'];
                                 }
                                    if ($_POST['amounttransact'] >= $acctbal)
                                       {
                                          $final_report .= "Insufficient Funds.";
                                       }
                                    else 
								   {
                                           $transctype = 'Bill Payment';
                                           $charges = '0.50';
                                           $acctbal = $acctbal - ($amounttransact + $charges);
                                           $result_sender = mysql_query("UPDATE members SET acctbal = '$acctbal -                                             ($amounttransact + $charges)' , amounttransact = '$amounttransact' ,  
										   statementdate = '$statementdate', transctype = '$transctype' , charges =                                           '$charges' WHERE username = '$_SESSION[username]'") or die(mysql_error                                           ());

                                           $final_report .= "Your Transfer has been successful.";
                                        }
						}
                                     else 
                                        {
                                           $final_report .= "Receivers Account is invalid.";

                                        }
		   }
        }
?>

 

Help will be really appreciated

Link to comment
https://forums.phpfreaks.com/topic/240659-fund-tranfer-form/#findComment-1237256
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.