Tranfering Amount to users account.

Hi experts. i have one quick question which i would like to know your suggestions on how to implement it.

i have one option of MY WALLET in my website. In mYwallet suppose i have $20 and i want to transfer to this money to my friends account. i will search my address book and suppose i found 5 friends. the number of friends can increase and decrease at any time.

i have provided the username and a textbox in the searched list so that i can add any amount to any user to send money to him. i am looking that whatever amount user enters it should match with his amount and if exceeds say that you have not enough money to transfer and if transferring user money is less than his own amount then it should deduct and show its own money. is this possible what i am trying
currently i am doing something like this:
 
<cfoutput query="amount">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Transfer Your Money to your Friend's Account</td></tr>
  <tr>
    <td>Welcome! #firstname# #lastname#</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Your Total amount in Wallet is <span style="color:##009900">USD #amount#</span></td>
  </tr>
</table>
</cfoutput>
<br />
<cfform method="post" preloader="no">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td colspan="2">Find Your Contact</td>
  </tr>
  <tr>
    <td width="24%"><strong>Keyword</strong></td>
    <td width="76%"><input type="text" name="keyword" id="keyword" class="textfield_effect" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="searchme" id="searchme" value="Contact" class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'"/></td>
  </tr>
  <tr>
    <td colspan="2">(* For Searching either enter the mobile number or the name of the person.)</td>
  </tr>
</table>
</cfform>
<cfif isDefined('form.searchme')>
	<cfform>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr align="left">
  	<th>S.No</th>
    <th>Person</th>
    <th>Amount to send</th>
  </tr>   
  <cfif getuser.recordcount>
  <cfoutput query="getUser">
  <tr>
    <td width="3%"><cfinput type="checkbox" name="addID" value="#addID#" required="yes" message="Error! Select 1 to send money"></td>
    <td width="47%">#addfirstname# #addlastname#</td>
    <td width="25%"><cfinput type="text" class="textfield_effect" style="width:70px;" name="amounttosend"></td>
  </tr>
  </cfoutput>
  <cfelse>
  <tr><td colspan="4" align="center">No record Found?</td></tr>
  </cfif>
</table>
</cfform>
</cfif>

Open in new window

LVL 16
Gurpreet Singh RandhawaCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurpreet Singh RandhawaCEOAuthor Commented:
Experts Please Guide me on this<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
0
gdemariaCommented:
>   i am looking that whatever amount user enters it should match with his amount and if exceeds say that you have not enough money to transfer and if transferring user money is less than his own amount then it should deduct and show its own money.

> is this possible what i am trying

Of course.

But you are not showing the action, you are just showing the form.   And it's unclear what values you are talking about.

Basically, all you need to do is use a simple CFIF statement to test the amount he is going to transfer against the amount available to transfer...


<cfif amountToTransfer gt amountAvailable>

     .... stop the action

</cfif>

You just need to get those two values from where-ever they are stored / entered and compare them.

0
Gurpreet Singh RandhawaCEOAuthor Commented:
Dude! I explain Here properly.

When i search i get three contacts, i mean i have three friends. i have amount of $10.

i will do $5 to first friend, $4 to second friend and try to do $2 to last friend, so it counts to $11 which is more than $10.

So i should stop the procesing and say check the amount in your wallet before tranferring.

If the amount is $9, it should add the relevant amount to respected users in their wallet and remaing should be shown to the main users account who transferred themoney. the amount should be deducted from the main users account and added to other users account.

i have the following code, but issue here is it checks for only TEXTBOX, well i think for the code to wok. the textboxes should have different names.

What i think that i should give each textbox the name of its username so each textbox should be unique.

what you say Mate?


<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
<cfquery datasource="#request.dsn#" name="getUser">
SELECT * FROM addressbook 
WHERE 
(addfirstname LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.keyword#%">
or 
addmobilenumber like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.keyword#%">)
AND 
adduserID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#session.clientuseruserid#">
</cfquery>
<cfform>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr align="left">
  	<th>S.No</th>
    <th>Person</th>
    <th>Amount to send</th>
  </tr>   
  <cfif getuser.recordcount>
  <cfoutput query="getUser">
  <tr>
    <td width="3%"><cfinput type="checkbox" name="addID" value="#addID#" required="yes" message="Error! Select 1 to send money"></td>
    <td width="47%">#addfirstname# #addlastname#</td>
    <td width="25%"><cfinput type="text" class="textfield_effect" style="width:70px;" name="amounttosend"></td>
  </tr>
  </cfoutput>
  <cfelse>
  <tr><td colspan="4" align="center">No record Found?</td></tr>
  </cfif>
</table>
</cfform>

Open in new window

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

gdemariaCommented:
That is clearer, thank you.  

I agree with you.  If you will allow them to check off more than one person, then you definitely need to associate the amount entered with which person is going to get the money !

You need to change your fields to multiple-record processing...

Add a number after each field so you can keep track of which records are associated with each other..

  addID1   addID2  addID3...
  amountToSend1,  amountToSend2, etc...

Below is some sample code, has nothing to do with your app but hopefully will give you a clearer idea of how to do this...




<cfset application.datasource = "YOUR DATASOURCE HERE">
 
<cfparam name="url.listingID" default="1">
<cfparam name="form.listingID" default="#url.listingID#">
 
<cfset variables.error = ""> <!---- will contain any error messages for display below later ----->
 
<!----- the action, will insert or update the record ----->
<cfif isDefined("form.doSave")>
  <cftry>
    <!---- loop through every record, add or update depending on whether they already had an ID ----->
    <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
 
    	<cfset form.photoname = form['photoname' & kk]>
    	<cfset form.description = form['description' & kk]>
    	<cfset form.photoID = form['photoID' & kk]>
 
             <cfquery name="updatePhotos" datasource="#application.datasource#">
              update photos
                set photoname = '#form.photoname#'
                  , description = '#form.description#'
              where photoID = #val(form.photoID)#
            </cfquery>
    </cfloop>
 
  <cfcatch type="Any">
     <cfset variables.error = cfcatch.message>
  </cfcatch>
  </cftry>
</cfif>
 
 
<!---- FETCH DATA
       Only fetch data from the database is there were no errors 
       If there were errors, show the error and the same data as entered, but not saved yet ------>
<cfif len(variables.error) eq 0>
    <!---- fetch the data from the database and convert into an array ----->
    <cfquery name="getData" datasource="#application.datasource#">
      SELECT ListingID, photoID, photoname, description
      FROM photos
      where ListingID = #val(form.ListingID)#
      order by photoName
    </cfquery>
    <cfloop query="getData">  <!---- create a form variable for every record, every column in the format:  form.columName1 ------>
      <cfloop index="aCol" list="#getData.columnList#">
        <cfset form[aCol & getData.currentRow] = getData[aCol][getData.currentRow]>
      </cfloop>
    </cfloop>
    <cfset form.totalRecords = getData.recordCount>
</cfif>
 
<cfif len(variables.error)> <!----- show the error ----->
 <div style="background-color:pink;color:maroon;padding:10px;font-weight:bold;">
  <cfoutput>Error: #variables.error#</cfoutput>
 </div>
</cfif>
 
<cfform name="myform" id="myform">
    <h1>ENTER .JPG NAMES &amp; DESCRIPTIVE TEXT HERE</h1>
    <cfoutput>
    <table width="525" border="0" cellpadding="2" cellspacing="2">
      <tr>
        <th width="144" scope="col">Photo Name</th>
        <th width="412" scope="col">Description</th>
      </tr>
      <!---- us a simple counter, not the ID to tack onto the variable names ----->
      <cfloop index="ii" from="1" to="#form.totalRecords#">
      <tr>
        <td valign="top"><input type="text" name="photoname#ii#" value="#form['photoname'&ii]#"/></td>
        <td><textarea name="description#ii#" cols="70" rows="3">#form['description' & ii]#</textarea>
            <input type="hidden" name="photoID#ii#" value="#form['photoID' & ii]#"> <!---- the primary key of the table ----->
        </td>
      </tr>
      </cfloop>
      <tr>
        <td>
        <cfoutput>
        <input type="hidden" name="listingID" value="#URL.ListingID#">
        <input type="Hidden" name="totalRecords" value="#form.totalRecords#">
        </cfoutput>
        </td>
        <td align="left"><cfinput type="submit" name="doSave" value="SAVE PHOTOS"/></td>
      </tr>
    </table>
    </cfoutput>
</cfform>

Open in new window

0
Gurpreet Singh RandhawaCEOAuthor Commented:
Thanks Mate i tried Your code with  a bit of changes but i think i had some issues:

my working is like this:


<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
<cfinclude template="val.cfm">
<cfif listlast(cgi.script_name, "/") eq "wallet.cfm">
  <cflocation url="index.cfm?action=wallet" addtoken="no">
</cfif>
<cfinvoke component="#request.cfcPath#.tools" method="getwallet" mobilenumber="#trim(session.clientmobile)#" returnvariable="amount"/>
<fieldset><legend>My Wallet</legend>
<cfif amount.recordcount>
<cfoutput query="amount">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Transfer Your Money to your Friend's Account</td></tr>
  <tr>
    <td>Welcome! #firstname# #lastname#</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Your Total amount in Wallet is <span style="color:##009900">#amount#</span></td>
  </tr>
  <tr>
    <td><div align="center">
      <cfform>
          <div align="left">
  <input type="submit" name="donate" id="donate" value="Donate to Charity" tabindex="1" class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'" style="width:150px;"/>
  &nbsp;&nbsp;
            <cfinput type="hidden" name="amount" value="#amount#">
              </div>
      </cfform>
      </div></td>
  </tr>
</table>
</cfoutput>
<cfif isDefined('form.donate')>
<div align="center">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5755722">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</cfif>
<br />
<cfform method="post" preloader="no">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td colspan="2">Find Your Contact</td>
  </tr>
  <tr>
    <td width="24%"><strong>Keyword</strong></td>
    <td width="76%"><input type="text" name="keyword" id="keyword" class="textfield_effect" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="searchme" id="searchme" value="Contact" class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'"/></td>
  </tr>
  <tr>
    <td colspan="2">(* For Searching either enter the mobile number or the name of the person.)</td>
  </tr>
</table>
</cfform>
<cfif isDefined('form.searchme')>
	<cfinclude template="search.cfm">
</cfif>
<cfelse>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Your Wallet Account</td></tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
<tr><td align="center">Your Wallet is Empty!</td></tr>
</table>
</cfif>
</fieldset>
 
the search.cfm Page:
 
<cfquery datasource="#request.dsn#" name="getUser">
SELECT * FROM addressbook 
WHERE 
(addfirstname LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.keyword#%">
or 
addmobilenumber like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.keyword#%">)
AND 
adduserID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#session.clientuseruserid#">
</cfquery>
<cfloop query="getUser">  <!---- create a form variable for every record, every column in the format:  form.columName1 ------>
      <cfloop index="aCol" list="#getUser.columnList#">
        <cfset form[aCol & getUser.currentRow] = getUser[aCol][getUser.currentRow]>
      </cfloop>
    </cfloop>
    <cfset form.totalRecords = getUser.recordCount>
<cfform>
<cfoutput>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr align="left">
    <th>Person</th>
    <th>Amount to send</th>
  </tr>   
  <cfif getuser.recordcount>
  <cfloop index="ii" from="1" to="#form.totalRecords#">
  <tr>
    <td width="47%">#addfirstname# #addlastname#</td>
    <td width="25%"><cfinput type="text" class="textfield_effect" style="width:70px;" name="amounttosend#i#" 
    value="#form['amounttosend' & ii]#"></td>
  </tr>
  </cfloop>
  <input type="Hidden" name="totalRecords" value="#form.totalRecords#">
  <cfelse>
  <tr><td colspan="4" align="center">No record Found?</td></tr>
  </cfif>
</table>
</cfoutput>
</cfform>
 
 but i am getting error:
 
 Variable ADDFIRSTNAME is undefined.
 
The error occurred in E:\domains\ibestcity.com\wwwroot\search.cfm: line 26
Called from E:\domains\ibestcity.com\wwwroot\wallet.cfm: line 70
Called from E:\domains\ibestcity.com\wwwroot\allpages.cfm: line 28
Called from E:\domains\ibestcity.com\wwwroot\index.cfm: line 108
 
24 :   <cfloop index="ii" from="1" to="#form.totalRecords#">
25 :   <tr>
26 :     <td width="47%">#addfirstname# #addlastname#</td>
27 :     <td width="25%"><cfinput type="text" class="textfield_effect" style="width:70px;" name="amounttosend#i#" 
28 :     value="#form['amounttosend' & ii]#"></td>
 
 
i know this error will occur but how do i modify it viably so it work according to what i set it here

Open in new window

0
gdemariaCommented:
You're getting that error when you submit?

It's because you are displaying the addFirstName, but you don't have a form field for it.

If there is any error, the page will not fetch from the database again, so it relies on a form field for everything you are displaying

Add two hidden fields...

     <td width="47%">#addfirstname# #addlastname#
            <input type="Hidden" name="addfirstName#i#" value="#form['addfirstName' & ii]#">
            <input type="Hidden" name="addlastname#i#" value="#form['addlastname' & ii]#">
         </td>

0
Gurpreet Singh RandhawaCEOAuthor Commented:
Hi mate i was updating the work so i have some issues working on it, i am not any error just my login stucked here.

i am just clikcing the SENDMONEY button to send the money to users account. but i have few considerations, before i run the update query i have two issues.

Suppose I AM THE PERSON WHO SENDS 5 TO ONE USER AND 5 TO OTHER USER.

I WANT THE UPDATE FOR ME SHOULD WORK AS DEDUCT 10 FROM ME AND IF THEY HAVE RECORD IN WALLET TABLE IT SHOULD UPDATE THEIR MONEY OR OTHER INSERT MONEY.

MY WALLET TABLE CONSISTS OF:

MOBILENUMBER AS UNIQUE AND AMOUNT AS FLOAT.


AND HOW SHOULD I VALIDATE IF AMOUNT TRANSFER IS GREATER THAN THE AVALIABLE AMOUNT IN THE WALLET.

pLEASE hELP gUIDE mE


<cfinclude template="val.cfm">
<cfif listlast(cgi.script_name, "/") eq "wallet.cfm">
  <cflocation url="index.cfm?action=wallet" addtoken="no">
</cfif>
<cfinvoke component="#request.cfcPath#.tools" method="getwallet" mobilenumber="#trim(session.clientmobile)#" returnvariable="amount"/>
<fieldset><legend>My Wallet</legend>
<cfif amount.recordcount>
<cfoutput query="amount">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Transfer Your Money to your Friend's Account</td></tr>
  <tr>
    <td>Welcome! #firstname# #lastname#</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Your Total amount in Wallet is <span style="color:##009900">#amount#</span></td>
  </tr>
  <tr><td><cfhttp url="http://finance.yahoo.com/d/quotes.csv?f=sl1d1t1&s=USDINR=X" method="get" result="yahooData">
	<cfset INR = listGetAt(yahooData.filecontent,2) /> 
		<cfdump var="#INR#" />
	</td>
  <tr>
    <td><div align="center">
      <cfform>
          <div align="left">
  <input type="submit" name="donate" id="donate" value="Donate to Charity" tabindex="1" class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'" style="width:150px;"/>
  &nbsp;&nbsp;
            <cfinput type="hidden" name="amount" value="#amount#">
              </div>
      </cfform>
      </div></td>
  </tr>
</table>
</cfoutput>
<cfif isDefined('form.donate')>
<div align="center">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5755722">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</cfif>
<br />
<cfform method="post" preloader="no">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td colspan="2">Find Your Contact</td>
  </tr>
  <tr>
    <td width="24%"><strong>Keyword</strong></td>
    <td width="76%"><input type="text" name="keyword" id="keyword" class="textfield_effect" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="searchme" id="searchme" value="Find" class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'"/></td>
  </tr>
  <tr>
    <td colspan="2">(* For Searching either enter the mobile number or the name of the person.)</td>
  </tr>
</table>
</cfform>
<cfif isDefined('form.searchme')>
<cfinvoke component="#request.cfcPath#.tools" method="getSearchData" 
keyword="#trim(form.keyword)#" clientID="#session.clientuseruserid#" returnvariable="getData"/>
	<cfloop query="getData">
  <!---- create a form variable for every record, every column in the format:  form.columName1 ------>
  <cfloop index="aCol" list="#getData.columnList#">
    <cfset form[aCol & getData.currentRow] = getData[aCol][getData.currentRow]>
  </cfloop>
</cfloop>
<cfset form.totalRecords = getData.recordCount>
<cfif isDefined("form.sendmoney")>
  <cftry>
    <!---- loop through every record, add or update depending on whether they already had an ID ----->
    <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
 
    	<cfset form.addfirstname = form['addfirstname' & kk]>
    	<cfset form.amounttosend = form['amounttosend' & kk]>
    	<cfset form.addID = form['addID' & kk]>
             <cfquery name="updateamount" datasource="#request.dsn#">
              update wallet 
              set photoname = '#form.photoname#'
                  , description = '#form.description#'
              where photoID = #val(form.photoID)#
            </cfquery>
    </cfloop>
 
  <cfcatch type="Any">
     <cfset variables.error = cfcatch.message>
  </cfcatch>
  </cftry>
</cfif>
<cfoutput>
  <cfform>
  <table width="100%" border="0" cellspacing="2" cellpadding="1">
    <tr align="left">
      <th width="681" scope="col">Name</th>
      <th width="308" scope="col">Amount to Transfer</th>
    </tr>
    <!---- us a simple counter, not the ID to tack onto the variable names ----->
    <cfloop index="ii" from="1" to="#form.totalRecords#">
      <tr align="left">
        <td valign="top">#form['addfirstname'&ii]# <input type="hidden" name="addfirstname#ii#" value="#form['addfirstname'&ii]#"/></td>
        <td><input type="text" name="amounttosend#ii#" size="5">
          <input type="hidden" name="addID#ii#" value="#form['addID' & ii]#">
          <!---- the primary key of the table ----->
        </td>
      </tr>
    </cfloop>
    <input type="Hidden" name="totalRecords" value="#form.totalRecords#">
    <tr>
      <td colspan="2" align="left"><cfinput type="submit" name="sendmoney" id="sendmoney" value="Send Money" 
  class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'"/></td>
    </tr>
  </table>
  </cfform>
</cfoutput> 
</cfif>
<cfelse>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Your Wallet Account</td></tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
<tr><td align="center">Your Wallet is Empty!</td></tr>
</table>
</cfif>
</fieldset>

Open in new window

0
gdemariaCommented:
Ok, we need to focus then on the action script.   The code you run when the user submits.  Do you have any of that written yet?  It would be easier to start from what you have then start from nothing.  But I don't see it in the code you posted.

Basically, we have to do multiple checks all within a CFTRANSACTION statement so that all actions are saved together.  If anything fails to save, all records are rolled back.

Here's the logic.

How much money do I have in my wallet?  MyAmount

How much money am I giving people now?  TotalToGive (add up each amount to give)

Compare myAmount with TotalToGive

If I have enough money, then deduct from my wallet and then loop to add to the other peoples' wallets.

Save Everything.
0
Gurpreet Singh RandhawaCEOAuthor Commented:
My Friends, I am so much Confused here. I have the following code:

i added one hidden fields where i display my total amount.

i have added the transaction before cftry tag.

i have suppose 4 fields. how can i compare the four fields. i ahve to go through a loop before i can match with each textfield by adding and then comparing with the original amount. Please Guide me. I am Just (:()

So first point. i think i cannot compare without looping all the textfields defined below with the main amount.

do the loop required different than defined below or the same one can be used.

after that i have to check from wallet table that the users mobilenumber exists, if yes then it should update else add.

i think i also need to add the mobilenumber where i am displaying users information because update and insert depends on mobilenumber. what u say abou it.


<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
<cfif isDefined('form.searchme')>
<cfinvoke component="#request.cfcPath#.tools" method="getSearchData" 
keyword="#trim(form.keyword)#" clientID="#session.clientuseruserid#" returnvariable="getData"/>
	<cfloop query="getData">
  <!---- create a form variable for every record, every column in the format:  form.columName1 ------>
  <cfloop index="aCol" list="#getData.columnList#">
    <cfset form[aCol & getData.currentRow] = getData[aCol][getData.currentRow]>
  </cfloop>
</cfloop>
<cfset form.totalRecords = getData.recordCount>
<cfif isDefined("form.sendmoney")>
<cftransaction>
  <cftry>
    <!---- loop through every record, add or update depending on whether they already had an ID ----->
    <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
 
    	<cfset form.addfirstname = form['addfirstname' & kk]>
    	<cfset form.amounttosend = form['amounttosend' & kk]>
    	<cfset form.addID = form['addID' & kk]>
             <cfquery name="updateamount" datasource="#request.dsn#">
              update wallet 
              set photoname = '#form.photoname#'
                  , description = '#form.description#'
              where photoID = #val(form.photoID)#
            </cfquery>
    </cfloop>
 
  <cfcatch type="Any">
     <cfset variables.error = cfcatch.message>
  </cfcatch>
  </cftry>
</cftransaction>  
</cfif>
<cfoutput>
  <cfform>
  <table width="100%" border="0" cellspacing="2" cellpadding="1">
    <tr align="left">
      <th width="681" scope="col">Name</th>
      <th width="308" scope="col">Amount to Transfer</th>
    </tr>
    <!---- us a simple counter, not the ID to tack onto the variable names ----->
    <cfloop index="ii" from="1" to="#form.totalRecords#">
      <tr align="left">
        <td valign="top">#form['addfirstname'&ii]# <input type="hidden" name="addfirstname#ii#" value="#form['addfirstname'&ii]#"/></td>
        <td><input type="text" name="amounttosend#ii#" size="5">
          <input type="hidden" name="addID#ii#" value="#form['addID' & ii]#">
          <!---- the primary key of the table ----->
        </td>
      </tr>
    </cfloop>
    <input type="Hidden" name="totalRecords" value="#form.totalRecords#">
    <cfinput type="hidden" name="amountihave" value="#amount.amount#">
    <tr>
      <td colspan="2" align="left"><cfinput type="submit" name="sendmoney" id="sendmoney" value="Send Money" 
  class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'"/></td>
    </tr>
  </table>
  </cfform>
</cfoutput> 
</cfif>
<cfelse>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Your Wallet Account</td></tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
<tr><td align="center">Your Wallet is Empty!</td></tr>
</table>
</cfif>
</fieldset>

Open in new window

0
gdemariaCommented:

Sounds like you have the steps right, why are you confused about doing a loop?

Here is a loop that can go right after <CFTRY> and before your other CLOOP that does the inserting.

This will add up the total and compare it to the amount the person has.

I don't see the variable that says how much the person has in his wallet, you you have to do that.
The variable I am using is called  "AmountIHave"

You need to get the amount he has an put it in that variable, or change the variable..


    <cfset form.totalToSend = 0>
    <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
		<cfset form.totalToSend = form.totalToSend + val(form['amounttosend' & kk])> <!--- add up amounts to send ---->
    </cfloop>
	<cfif form.TotalToSend gt AmountIHave>
	  <cfthrow message="You are trying to send more than you have.  You only have #amountIhave#">
	</cfif>

Open in new window

0
Gurpreet Singh RandhawaCEOAuthor Commented:
Hi Thanks I just tried and got some diffrent results. my whole work is under the attach code snippet work.

i added two hidden fields. one is the mobilenumber of the user who sends the money and the other is.amountihave which shows the exact amount the user have in its account.

now i made some transactions like below:

  • It will deduct the money from the users account who send the money.
  • then it checks for other users that there details exist in the wallet table, if yes update else insert.
  • but it shows invalid results.
First I did some stuff.

i have money in my account as 200. i found 2 results while searching and send then 10 each. now when i looked at my database. my own money cam to 148 and others users who were not in the wallet table added as a new record with 10 in each.

now i again did the process to transfer another 20 each to bother users.

It did some invalid combination. It increased my amount to 148 to 160 and added 20 each to other users account by overwriting 10. i mean now they have 20 each. but t should work as 10+20 =30 in each users account
i think i am doing some very wired bad math here but i think my problem lies with the loop tag.



<cfif isDefined("form.sendmoney")>
<cftransaction>
<cfset form.totalToSend = 0>
    <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
		<cfset form.totalToSend = form.totalToSend + val(form['amounttosend' & kk])> <!--- add up amounts to send ---->
    </cfloop>
   <cfif form.TotalToSend gt form.amountihave>
	  <cfset msg = "You are trying to send more than you have.  You only have INR #amountIhave#">
   <cfelse>   
  <cftry>
    <!---- loop through every record, add or update depending on whether they already had an ID ----->
    <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
    	<cfset form.addfirstname = form['addfirstname' & kk]>
    	<cfset form.amounttosend = form['amounttosend' & kk]>
    	<cfset form.addID = form['addID' & kk]>
        <cfset form.addmobilenumber = form['addmobilenumber' & kk]>
            <cfquery name="updateamount" datasource="#request.dsn#">
              update wallet 
              set amount = #form.amountihave# - #form.totaltosend#
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.Moneysender)#">
            </cfquery>
            <cfquery name="getnumber" datasource="#request.dsn#">
              SELECT * from wallet 
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">
            </cfquery>
            <cfif getnumber.recordcount>
             <cfquery name="updateotherUsersamount" datasource="#request.dsn#">
              update wallet 
              set amount =+ #form.amounttosend#
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">
            </cfquery>
            <cfelse>
             <cfquery name="InsertotherUsersamount" datasource="#request.dsn#">
              INSERT INTO wallet(mobilenumber, amount) 
              VALUES(<cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">,
              <cfqueryparam cfsqltype="cf_sql_float" value="#trim(form.amounttosend)#">)
            </cfquery>
            </cfif>
            <cfset msg = "Cool! Your Details Processed">
    </cfloop>
  <cfcatch type="Any">
     <cfset msg = "Error! #cfcatch.Detail# #cfcatch.message#">
  </cfcatch>
  </cftry>
  </cfif>
</cftransaction>  
</cfif>
<cfoutput>
  <cfform>
  <table width="100%" border="0" cellspacing="2" cellpadding="1">
    <tr align="left">
      <th width="681" scope="col">Name</th>
      <th width="308" scope="col">Amount to Transfer</th>
    </tr>
    <cfif isDefined('msg')><tr><td colspan="2" align="center" class="errString"><cfoutput>#trim(msg)#</cfoutput></td></tr></cfif>
    <!---- us a simple counter, not the ID to tack onto the variable names ----->
    <cfloop index="ii" from="1" to="#form.totalRecords#">
      <tr align="left">
        <td valign="top">#form['addfirstname'&ii]# <input type="hidden" name="addfirstname#ii#" value="#form['addfirstname'&ii]#"/></td>
        <td><input type="text" name="amounttosend#ii#" size="5">
          <input type="hidden" name="addID#ii#" value="#form['addID' & ii]#">
          <input type="hidden" name="addmobilenumber#ii#" value="#form['addmobilenumber' & ii]#">
          <!---- the primary key of the table ----->
        </td>
      </tr>
    </cfloop>
    <input type="Hidden" name="totalRecords" value="#form.totalRecords#">
    <cfinput type="hidden" name="amountihave" value="#amount.amount#">
    <cfinput type="hidden" name="Moneysender" value="#session.clientmobile#">
    <tr>
      <td colspan="2" align="left"><cfinput type="submit" name="sendmoney" id="sendmoney" value="Send Money" 
  class="inputButton" onMouseOver="this.className='inputButton_over'" onMouseOut="this.className='inputButton'"/></td>
    </tr>
  </table>
  </cfform>
</cfoutput> 
</cfif>
<cfelse>
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <tr>
    <td><caption><img src="images/wallet.gif">&nbsp;Wallet</caption></td>
  </tr>
  <tr><td colspan="2" align="center">Your Wallet Account</td></tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
<tr><td align="center">Your Wallet is Empty!</td></tr>
</table>
</cfif>
</fieldset>

Open in new window

0
gdemariaCommented:


This update statement, is deducting from the SENDER's wallet...

            <cfquery name="updateamount" datasource="#request.dsn#">
              update wallet
              set amount = #form.amountihave# - #form.totaltosend#
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.Moneysender)#">
            </cfquery>

You have it INSIDE the CFLOOP.  So this update is running once for every person you're giving money to.

You need to move it before or after the CFLOOP, so you only run it once.


0
gdemariaCommented:
This approach may work well too...

Keep it inside the CFLOOP and only deduct the amount sent during each loop....


       <cfloop index="kk" from="1" to="#val(form.totalRecords)#">
               <cfset form.addfirstname = form['addfirstname' & kk]>
                <cfset form.amounttosend = form['amounttosend' & kk]>
           <cfset form.addmobilenumber = form['addmobilenumber' & kk]>
             <cfset form.addID = form['addID' & kk]>
            <cfquery name="getnumber" datasource="#request.dsn#">
              SELECT * from wallet
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">
            </cfquery>
            <cfif getnumber.recordcount>
                <cfquery name="updateotherUsersamount" datasource="#request.dsn#">
                 update wallet
                   set amount = isNull(amount,0) + #form.amounttosend#
                 where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">
               </cfquery>
            <cfelse>
               <cfquery name="InsertotherUsersamount" datasource="#request.dsn#">
                INSERT INTO wallet(mobilenumber, amount)
                VALUES(<cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">,
                       <cfqueryparam cfsqltype="cf_sql_float" value="#val(form.amounttosend)#">)
               </cfquery>
            </cfif>
            <cfquery name="updateamount" datasource="#request.dsn#">
              update wallet
              set amount = isNull(amount,0) - #val(form.amounttosend)#
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(session.clientmobile)#">
            </cfquery>
            <cfset msg = "Cool! Your Details Processed">
       </cfloop>

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gdemariaCommented:
Notice this change in your where clause...

  where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(session.clientmobile)#">

I used the session variable for clientMobile.

When you add values to hidden fields they can be easily changed/hacked by the user.  So it would be easy for me to change this to deduct from someone else's wallet instead of from mine.

After you get this working, you should review for security and hacking.
0
Gurpreet Singh RandhawaCEOAuthor Commented:
i am getting this error:



 Error Executing Database Query.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0) + 10 where mobilenumber = 919976567667' at line 2
 
The error occurred in C:\Inetpub\wwwroot\ibestcity\wallet.cfm: line 103
 
101 :                  update wallet
102 :                    set amount = isNull(amount,0) + #form.amounttosend#
103 :                  where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(form.addmobilenumber)#">
104 :                </cfquery>
105 :             <cfelse>
 
 
First time i run it i got error at line:
 
115 which contains this query:
 
<cfquery name="updateamount" datasource="#request.dsn#">
              update wallet
              set amount = isNull(amount,0) - #val(form.amounttosend)#
              where mobilenumber = <cfqueryparam cfsqltype="cf_sql_numeric" value="#trim(session.clientmobile)#">
            </cfquery>
 
Then i did refresh and got error in line 104 please check what is wrong here

Open in new window

0
gdemariaCommented:
Oh, you're using MySQL.   It seems mySQL doesn't have isNull() function.

Is "amount"  a required integer?   If it is NOT NULL on the table, then you can remove isNull() because the amount will never be null.   If it is not required and 'amount' could be null, use the mySQL equivalent
0
Gurpreet Singh RandhawaCEOAuthor Commented:
Cool Thanks, I used this Mysql Euivalent COALESCE(), Although isNull() works in Mysql but its behaviour is bit different from mssql server
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.