Jump to content

help with inserting only after payment


toolman

Recommended Posts

Hi there,

 

I have some code that inserts into a database, but I want to set it up so that it only enters into the database when a user pays via PayPal. I already have the PayPal code set up, but I don't know how to set it up to only insert when a user pays.  At the moment it inserts into the database if the user completes a form and then hits back without paying.

 

Any help would be great.

 

This is my code:

 



<?php
require_once 'tabconf.php';


if(!empty($_POST['ad_title'])&&!empty($_POST['ad_text'])&&!empty($_POST['ad_url'])&&!empty($_POST['contact_email'])){
  if(substr($_POST['ad_url'], 0, 4)!='http') {
    $_POST['ad_url'] = 'http://'.$_POST['ad_url'];
  }

  $query = "INSERT INTO tabAdBids
    (ad_title, ad_text, ad_url, contact_email, date_placed)
    VALUES('".$_POST['ad_title']."', '".$_POST['ad_text']."', '".$_POST['ad_url']."', '".$_POST['contact_email']."', NOW())";

  $result = mysql_query($query);
  $rowid = mysql_insert_id();

  $query = "SELECT paypal_id, home_url FROM tabAdministration";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  $paypalid = $row['paypal_id'];
  $home_url = $row['home_url'];

  $fp = fopen('tab_payad.tpl', 'r');
  while(!feof($fp)){
    $body .= fgets($fp, 1024);
  }

  $ppform = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="Text Ad Bid">
<input type="hidden" name="item_number" value="'.$rowid.'">
<input type="hidden" name="amount" value="1.00">
<input type="hidden" name="shipping" value="0">
<input type="hidden" name="shipping2" value="0">
<input type="hidden" name="handling_cart" value="0">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="'.$home_url.'pp_return.php">
<input type="hidden" name="cancel_return" value="'.$home_url.'pp_creturn.php">
<input type="hidden" name="notify_url" value="'.$home_url.'pp_notify.php" />
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="http://www.domain.com/images/paypal.jpg" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
</form>';

  $body = str_replace('{tab_pp_button}', $ppform, $body);

  print $body;
}else{

  $query = "SELECT ad_title_length, ad_text_length FROM tabAdministration";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);

  $fp = fopen('tab_placead.tpl', 'r');
  while(!feof($fp)){
    $body .= fgets($fp, 1024);
  }
  $body = str_replace('{tab_title_max}', $row['ad_title_length'], $body);
  $body = str_replace('{tab_text_max}', $row['ad_text_length'], $body);

  $body = str_replace('{tab_title}', $_POST['ad_title'], $body);
  $body = str_replace('{tab_url}', $_POST['ad_url'], $body);
  $body = str_replace('{tab_text}', $_POST['ad_text'], $body);
  $body = str_replace('{tab_email}', $_POST['contact_email'], $body);

  print $body;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/201863-help-with-inserting-only-after-payment/
Share on other sites

Paypal uses whats called IPN (Instant Payment Notification). You should have all your customer's data saved with some kind of identifier. Post your form to paypal including the identifier. They will post the results back to a page you have designated. This will allow you to match the results they are sending you with your saved data via your identifier so you can now process the order.

Archived

This topic is now archived and is closed to further replies.

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