1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple PayPal script for registration form.

Discussion in 'PHP' started by derek34, Dec 1, 2007.

  1. #1
    Hi
    I'm designing a script for someone that wants to have an online registration form where people can sign up for a certain event. There is also a cost to attend the event. So I need to have something where they can pay online. PayPal seems like the easiest way to do this. Can somebody show me how to design a script that forwards the person to PayPal to pay for the item and then sends them back to the website after they have paid?
     
    derek34, Dec 1, 2007 IP
  2. Xexi

    Xexi Well-Known Member

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Paypal has a feature called paypal IPN (Instant Payment Notification).

    There are a few premade aftermarket scripts available on other sites if you don't know how to set it up yourself, using their examples.
     
    Xexi, Dec 1, 2007 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    The cleanest way to set this up is to use a form to submit their data the the DB and the after submission they are directed to PayPal for payment. The IPN function is used to mark the tranaction as paid in your DB.
     
    Colbyt, Dec 1, 2007 IP
  4. mrsoldierruel

    mrsoldierruel Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sound good but I cant understand it....? any guides?:)
     
    mrsoldierruel, Dec 18, 2007 IP
  5. alhen

    alhen Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have done this before. The way I did it was to create the form, like you said, that submits the info into a database. On the page you submit (POST) to, You can also include the PayPal form. For PayPal, you just need to open a (free) business account, and create the form that you can use. It will look something like this:

    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
      <input name="q0" type="hidden" value="1">
      <input name="submit" type="image" src="images/paynow.gif" alt="Make payments with PayPal - it's fast, free and secure!" width="121" height="21" border="0">
      <img alt="" border="0" src="https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif" width="1" height="1">
      <input type="hidden" name="add" value="1">
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="business" value="YOUREMAIL@DOMAIN.COM">
      <input type="hidden" name="item_name" value="DESCRIPTION OF YOUR ITEM">
      <input type="hidden" name="item_number" value="ITEM NUMBER, IF YOU HAVE ONE">
      <input type="hidden" name="amount" value="DOLLAR AMOUNT YOU WANT">
      <input type="hidden" name="shipping" value="0.00">
      <input type="hidden" name="buyer_credit_promo_code" value="">
      <input type="hidden" name="buyer_credit_product_category" value="">
      <input type="hidden" name="buyer_credit_shipping_method" value="">
      <input type="hidden" name="buyer_credit_user_address_change" value="">
      <input type="hidden" name="no_shipping" value="0">
      <input type="hidden" name="no_note" value="1">
      <input type="hidden" name="currency_code" value="USD">
      <input type="hidden" name="tax" value="0.00">
      <input type="hidden" name="lc" value="US">
      <input type="hidden" name="bn" value="PP-ShopCartBF">
    </form>
    
    Code (markup):
    Now, what I did is I took some of the info that was subitted to the form and used it to display the form only if they chose a certain option.

    So if they say "Yes" you can show them the form with a code like this:
    <? if ($attending == "Yes") { ?>
    //enter paypal script here
    <? } ?>
    PHP:
    Or if they say "No", you would do something like this:
    <? if ($attending == "No") { ?>
    //don't put paypal script, just say something like "thank you for letting us know you're not attending
    <? } ?>
    PHP:
    So the whole page could look something like this.

    <?
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $email=$_POST['email'];
    $attending=$_POST['attending'];
    
    MYSQL_CONNECT(localhost, your_username, your_password) OR DIE("DB connection unavailable");
    @mysql_select_db( "your_database") or die( "Unable to select database"); 
    
    $query = "INSERT INTO your_table VALUES ('', '$firstname', '$lastname', '$email', '$attending')";
    mysql_query($query);
    
    mysql_close();
    ?>
    <html>
    <head>
    <title>Web Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <? if ($attending == "Yes") { ?>
    Thanks for attending, you can pay your fee below <br>
    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
      <input name="q0" type="hidden" value="1">
      <input name="submit" type="image" src="images/paynow.gif" alt="Make payments with PayPal - it's fast, free and secure!" width="121" height="21" border="0" onClick='alert("**PLEASE READ** On the next page, please click UPDATE CART before you check out. On the page after that, you may login if you have a PayPal account, or click CONTINUE (below credit card logos) to pay if you do not have a PayPal account. Thank You !!!")'>
      <img alt="" border="0" src="https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif" width="1" height="1">
      <input type="hidden" name="add" value="1">
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="business" value="YOUREMAIL@DOMAIN.COM">
      <input type="hidden" name="item_name" value="DESCRIPTION">
      <input type="hidden" name="item_number" value="item NUMBER">
      <input type="hidden" name="amount" value="PRICE">
      <input type="hidden" name="shipping" value="0.00">
      <input type="hidden" name="buyer_credit_promo_code" value="">
      <input type="hidden" name="buyer_credit_product_category" value="">
      <input type="hidden" name="buyer_credit_shipping_method" value="">
      <input type="hidden" name="buyer_credit_user_address_change" value="">
      <input type="hidden" name="no_shipping" value="0">
      <input type="hidden" name="no_note" value="1">
      <input type="hidden" name="currency_code" value="USD">
      <input type="hidden" name="tax" value="0.00">
      <input type="hidden" name="lc" value="US">
      <input type="hidden" name="bn" value="PP-ShopCartBF">
    </form>
    <? } ?>
    <? if ($attending == "No") { ?>
    Thank for for your RSVP that you are not attending
    <? } ?>
    </body>
    </html>
    Code (markup):
     
    alhen, Dec 18, 2007 IP
  6. alhen

    alhen Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Furthermore, if you need to have different prices, you can pull that info from the first form too.

    Let's say you have two levels of registration, $10 and $20. You can ask which one they choose on your form, then send that to your database AND to your paypal form. So you would just need to add corresponding script in your PHP and paypal form like this:

    <?
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $email=$_POST['email'];
    $attending=$_POST['attending'];
    $amount=$_POST['amount'];
    
    MYSQL_CONNECT(localhost, your_username, your_password) OR DIE("DB connection unavailable");
    @mysql_select_db( "your_database") or die( "Unable to select database"); 
    
    $query = "INSERT INTO your_table VALUES ('', '$firstname', '$lastname', '$email', '$attending', 'amount')";
    mysql_query($query);
    
    mysql_close();
    ?>
    <? if ($attending == "Yes") { ?>
    Thanks for attending, you can pay your fee below <br>
    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
      <input name="q0" type="hidden" value="1">
      <input name="submit" type="image" src="images/paynow.gif" alt="Make payments with PayPal - it's fast, free and secure!" width="121" height="21" border="0" onClick='alert("**PLEASE READ** On the next page, please click UPDATE CART before you check out. On the page after that, you may login if you have a PayPal account, or click CONTINUE (below credit card logos) to pay if you do not have a PayPal account. Thank You !!!")'>
      <img alt="" border="0" src="https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif" width="1" height="1">
      <input type="hidden" name="add" value="1">
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="business" value="YOUREMAIL@DOMAIN.COM">
      <input type="hidden" name="item_name" value="DESCRIPTION">
      <input type="hidden" name="item_number" value="item NUMBER">
      <input type="hidden" name="amount" value="<? echo "$total"; ?>">
      <input type="hidden" name="shipping" value="0.00">
      <input type="hidden" name="buyer_credit_promo_code" value="">
      <input type="hidden" name="buyer_credit_product_category" value="">
      <input type="hidden" name="buyer_credit_shipping_method" value="">
      <input type="hidden" name="buyer_credit_user_address_change" value="">
      <input type="hidden" name="no_shipping" value="0">
      <input type="hidden" name="no_note" value="1">
      <input type="hidden" name="currency_code" value="USD">
      <input type="hidden" name="tax" value="0.00">
      <input type="hidden" name="lc" value="US">
      <input type="hidden" name="bn" value="PP-ShopCartBF">
    </form>
    <? } ?>
    <? if ($attending == "No") { ?>
    Thank for for your RSVP that you are not attending
    <? } ?>
    PHP:
    So, not only did I add that field to the PHP script at the top, but I also added:
    <? echo "$total"; ?>
    PHP:
    in the paypal form for the dollar amount.
     
    alhen, Dec 18, 2007 IP
  7. Quevin

    Quevin Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This may be like what I'm looking for. We have only a few products, and want someone to choose a shipping method that changes based on quantity. And price changes after 10 items to offer a volume discount. JavaScript could do this on the front-end, but that's unreliable and you always need something on the server-side.

    People are getting confused when they get to Paypal, and need to decide on shipping costs. Many mistakenly choose "pick up" when they're not local.

    However, if I use Paypal IPN, will I need SSL and the DB setup?

    Would also like a quote, and recommendation whether what we really need is a little shopping cart program, or if this will suffice until we're ready for something bigger like ProStores. Or whatever. Thanks!
     
    Quevin, Jul 15, 2008 IP
  8. rafderamas

    rafderamas Active Member

    Messages:
    288
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    This might sound annoying but can anybody help me on how to do this?
     
    rafderamas, Jul 22, 2010 IP