using a button to perform tasks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rlm51
    New Member
    • Mar 2007
    • 29

    using a button to perform tasks

    Hey everyone ...

    I have a button on my page:
    [code=html]
    <input name="button" type="button" class="style3" onclick="window .print()" value="Print Coupon" />
    [/code]

    that uses window.print() to print a coupon. I would like to add a function to the code that updates a field in a database that tracks how many coupons are printed. Is there a way to add this function:
    [code=php]
    $CouponNo = $CouponNo + 1;
    mysql_query("UP DATE tbl_depts SET CouponNo = $CouponNo WHERE `key` = $spec");
    [/code]
    to that button?

    Thanks for any help

    Robert
    Last edited by Atli; Dec 9 '07, 08:27 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi Robert.

    HTML and JavaScript, being server-side monstrosities, can not directly interact with PHP, as that is a server-side language.

    You can, however, use tools such as Ajax to make HTTP requests on your server to execute PHP scripts.

    For example, if you were to put your PHP code, the one you posted above, in a PHP file, you could use Ajax to request that file from your server, which would effectively increment you coupon count.

    Comment

    • rlm51
      New Member
      • Mar 2007
      • 29

      #3
      Thanks for your reply. I actually figured it out over the weekend.
      In Dreamweaver, you can tag more than one behavior to the "onclick" so I ended up using this code:
      [code=html]
      <input name="button" type="button" class="style3" onclick="window .print() ;MM_goToURL('pa rent','../DeptSpecials.ph p');<?PHP $CouponNo = $CouponNo + 1 ?>;return document.MM_ret urnValue" value="Print Coupon" />
      [/code]

      Works great ...

      Again, thanks for your help.

      Hope everyone has a great holiday season.

      Robert
      Last edited by Atli; Dec 11 '07, 09:58 AM. Reason: Added [code] tags.

      Comment

      Working...