A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: PHP update total field - going crazy!

  1. #1
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929

    PHP update total field - going crazy!

    Making myself crazy here. Only have basic php knowledge and I'm trying to create a form for a client where they can enter the number of a particular type of ticket they want to purchase, and it needs to update a "total" field for that type of ticket and the overall total. Once the fields are current, it just needs to pass the total to another site that handles the payment processing...

    I can't get the totals to work and I can't get the total to pass to the form as anything other than a static value number...GRRR!!!

    I've tried doing this 2 ways, using a function and not...neither one updates the fields...

    I pasted the code below and also attached the two files...

    Here's the non-function method...you can see at the end of this one where I try to send the value as a variable

    Code:
    <form method='Redirect' action= 'URL of payment processing site'>
    <table width="600" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="4"><strong>Purchase tickets:</strong></td>
        </tr>
      <tr>
        <td width="32%">Tickets</td>
        <td width="20%"><div align="center">Price</div></td>
        <td width="17%"><div align="center">Number</div></td>
        <td width="150"><div align="center">Total</div></td>
      </tr>
      <tr>
        <td>Concert only</td>
        <td><div align="center">$25</div></td>
        <td><div align="center"><input type="text" name="num_concert" id="num_concert" size="15" value="0" onchange="document.myform.total_concert.value=25*parseInt(this.value);document.myform.total_total.value=parseInt(document.myform.total_reception.value)+parseInt(document.myform.total_donate.value)+25*parseInt(this.value);" /></div></td>
        <td><div align="center">=$ <input type="text" name="total_concert" id="total_concert" size="15" value="0" /></div></td>
      </tr>
      <tr>
        <td>Concert plus reception</td>
        <td><div align="center">$75</div></td>
        <td><div align="center"><input type="text" name="num_reception" id="num_reception" size="15" value="0" onchange="document.myform.total_reception.value=75*parseInt(this.value);document.myform.total_total.value=parseInt(document.myform.total_concert.value)+parseInt(document.myform.total_donate.value)+75*parseInt(this.value);" /></div></td>
        <td><div align="center">=$ <input type="text" name="total_reception" id="total_reception" size="15" value="0" /></div></td>
      </tr>
      
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><div align="right"><strong>Total:</strong></div></td>
        <td><div align="center">=$ <input type="text" name="total_total" id="total_total" size="15" value="0" /></div></td>
      </tr>
    </table>
    
    
    <table cellSpacing='0' cellPadding='0' border='0'>
    
    <tr>
    <td align='right' width='300'></td>
    <td align='left' width='200'><input type='hidden' name='pg_api_login_id' value='xxx'/></td>
    </tr>
    <tr>
    <td align='right' width='300'><div align="left"><b>Total: </b></div></td>
    <td align='left' width='200'><input type='hidden' name='pg_total_amount'value=total_total /><br></td></tr><tr><td align='right' width='300'></td><td align='left' width='200'><INPUT TYPE=SUBMIT value='Pay Now'><br></td></tr>
    <tr>
      <td align='right'></td>
      <td align='left'>&nbsp;</td>
    </tr>
    </table>
    </form>

    and here's the function method...which doesn't work any better...

    Code:
    <!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=iso-8859-1" />
    <title>Untitled Document</title>
    
    <script type="text/javascript">
    var qty1, qty2, total1;
    var calculate = function() {
    function ids( elem, num ) {
    if ( num )
    return (( document.getElementById ) ? parseFloat( document.getElementById( elem ).value ) : parseFloat( document.all[elem].value ));
    else
    return elem = (( document.getElementById ) ? document.getElementById(elem) : document.all[elem] );
    }
    ids("num_concert").onchange = function() {
    qty1 = ids( this.id, true );
    qty1 = ( qty1 <= 0 ) ? alert("Quantity should be => 0") : ids("total_concert").value = ( qty1 * ids("val1", true ));
    };
    ids("num_reception").onchange = function() {
    qty2 = ids( this.id, true );
    qty2 = ( qty2 <= 0 ) ? alert("Quantity should be => 0") : ids("total_reception").value = qty2 * ids("val2", true);
    };
    ids("total_total").value = "$" + ((( ids("total_concert", true )) + ids("total_reception", true));
    };
    window.onkeypress = calculate;
    </script>
    </head>
    
    <body>
    
    
    <form method='Redirect' action= 'URL for payment processing site'>
    <table width="600" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="4"><strong>Purchase tickets:</strong></td>
        </tr>
      <tr>
        <td width="32%">Tickets</td>
        <td width="17%"><div align="center">Number</div></td>
        <td width="20%"><div align="center">Price</div></td>
        <td width="150"><div align="center">Total</div></td>
      </tr>
      <tr>
        <td>Concert only</td>
    	
    <td><input type="number" id="num_concert" name="num_concert" value="" size="15" /></td>
    <td><input type="hidden" id="val1" name="val1" value="25" />$25</td>
    <td><input type="text" id="total_concert" name="total_concert" value="0" size="15" /></td>
    
      </tr>
      <tr>
        <td>Concert plus reception</td>
        <td><div align="center">$75</div></td>
        <td><div align="center"><input type="text" name="num_reception" id="num_reception" size="15" value="0" /></div></td>
        <td><div align="center">=$ <input type="text" name="total_reception" id="total_reception" size="15" value="0" /></div></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><div align="right"><strong>Total:</strong></div></td>
        <td><div align="center">=$ <input type="text" name="total_total" id="total_total" size="15" value="0" /></div></td>
      </tr>
    </table>
    
    
    <table cellSpacing='0' cellPadding='0' border='0'>
    
    <tr>
    <td align='right' width='300'></td>
    <td align='left' width='200'><input type='hidden' name='pg_api_login_id' value='xxx'/></td>
    </tr>
    <tr>
    <td align='right' width='300'><div align="left"><b>Total: </b></div></td>
    <td align='left' width='200'><input type='hidden' name='pg_total_amount'value='30' /><br></td></tr><tr><td align='right' width='300'></td><td align='left' width='200'><INPUT TYPE=SUBMIT value='Pay Now'><br></td></tr>
    <tr>
      <td align='right'></td>
      <td align='left'>&nbsp;</td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    Attached Files Attached Files
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    GOT IT!!!

    WOOHOO!! Just had to add the name to my form (in the non-function method), so that it referenced that as the document...NICE!!!

    Now, I just need to be able to pass the total_total value through on Submit...

    The Total field is displaying the right value, but trying either of the following gives me an error that the value must be a number greater than 0...

    Code:
    <input type='hidden' name='pg_total_amount' value=total_total />
    or

    Code:
    <input type='hidden' name='pg_total_amount' value='total_total' />
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    Hmm...also tried this and it says I don't have permission to access the page:

    Code:
    <input type='hidden' name='pg_total_amount' value="<?=$total_total?>" />
    then I tried this and it goes through correctly...hmm...

    Code:
    <input type='hidden' name='pg_total_amount' value="50" />
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    try:

    <input type='hidden' name='pg_total_amount' value="<?php echo $total_total ?>" />
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    Hmmm...I still get a "You are not authorized to view this page"
    So weird...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center