Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:27:49+00:00 2026-06-16T21:27:49+00:00

I have this script that is supposed to insert the information into a MySQL

  • 0

I have this script that is supposed to insert the information into a MySQL table, but for some reason it will only save it in the ipn.log file but doesn’t run the insert query. Here is the code that I have.

<?php 

//Lets do MySql connection stuff 
$mysql_host = 'SERVER'; //Leave at localhost 
$mysql_user = 'USER'; //DB User 
$mysql_pass = 'PASSWORD'; //DB Pass 
$mysql_db = 'DATABASE'; //DB Name 

//------------------------------------------------------------------ 
// Open log file (in append mode) and write the current time into it. 
// Open the DB Connection. Open the actual database. 
//------------------------------------------------------------------- 
$log = fopen("ipn.log", "a"); 
fwrite($log, "\n\nipn - ".gmstrftime("%b %d %Y %H:%M:%S", time())."\n"); 
$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
mysql_select_db($mysql_db, $db); 

//------------------------------------------------ 
// Read post from PayPal system and create reply 
// starting with: 'cmd=_notify-validate'... 
// then repeating all values sent - VALIDATION. 
//------------------------------------------------ 
$postvars = array(); 

while(list($key, $value) = each($_POST)) 
{ 
  $postvars[] = $key; 
} 
$req = 'cmd=_notify-validate'; 

for($var = 0; $var < count($postvars); $var++) 
{ 
  $postvar_key = $postvars[$var]; 
  $postvar_value = $$postvars[$var]; 
  $req .= "&".$postvar_key."=".urlencode($postvar_value); 
} 

//-------------------------------------------- 
// Create message to post back to PayPal... 
// Open a socket to the PayPal server... 
//-------------------------------------------- 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: ".strlen($req)."\r\n\r\n"; 
$fp = fsockopen("www.paypal.com", 80, $errno, $errstr, 30); 

//--------------------------------------------- 
fwrite($log, "Vals: ". $invoice." ". $receiver_email." ". $item_name." ". $item_number." ". $quantity." ". $payment_status." ". $pending_reason." ".$payment_date." ". $payment_gross." ". $payment_fee." ". $txn_id." ". $txn_type." ". $first_name." ". $last_name." ". $address_street." ". $address_city." ". $address_state . " ".$address_zip." ". $address_country." ". $address_status." ". $payer_email. " ". $payer_status." ". $payment_type." ". $notify_version." ". $verify_sign. "\ n"); 

// assign posted variables to local variables 
$item_name = $_POST['item_name']; 
$item_number = $_POST['item_number']; 
$payment_status = $_POST['payment_status']; 
$payment_amount = $_POST['mc_gross']; 
$payment_currency = $_POST['mc_currency']; 
$txn_id = $_POST['txn_id']; 
$receiver_email = $_POST['receiver_email']; 
$payer_email = $_POST['payer_email']; 

//---------------------------------------------------------------------- 
// Check HTTP connection made to PayPal OK, If not, print an error msg 
//---------------------------------------------------------------------- 
if(!$fp) 
{ 
  echo $errstr."(".$errno.")"; 
  fwrite($log, "Failed to open HTTP connection!"); 
  $res = "FAILED"; 
} 
//-------------------------------------------------------- 
// If connected OK, write the posted values back, then... 
//-------------------------------------------------------- 
else 
{ 
  fputs($fp, $header . $req); 
  //------------------------------------------- 
  // ...read the results of the verification... 
  // If VERIFIED = continue to process the TX... 
  //------------------------------------------- 
  while(!feof($fp)) 
  { 
    $res = fgets($fp, 1024); 
    if(strcmp($res, "VERIFIED") == 0) 
    { 
      //-------------------------------------- 
      // Insert Transaction details into DB. 
      //-------------------------------------- 
      $qry = "INSERT INTO DONATIONS (invoice, receiver_email, item_name, item_number, quantity, payment_status, pending_reason, payment_date, payment_gross, payment_fee, txn_id, txn_type, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_status, payer_email, payer_status, payment_type, notify_version, verify_sign) VALUES('$invoice', '$receiver_email', '$item_name', '$item_number', '$quantity', '$payment_status', '$pending_reason', '$payment_date', '$payment_gross', '$payment_fee', '$txn_id', '$txn_type', '$first_name', '$last_name', '$address_street', '$address_city', '$address_state', '$address_zip', '$address_country', '$address_status', '$payer_email', '$payer_status ', '$payment_type', '$notify_version', '$verify_sign')"; 
      $result = mysql_query($qry); 
    } 
  } 
} 
//------------------------------------------- 
// Close PayPal Connection, Log File and DB. 
//------------------------------------------- 
fclose($fp); 
fclose($log); 
mysql_close($db); 

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:27:50+00:00Added an answer on June 16, 2026 at 9:27 pm

    The best way is too find out the “some reason” by putting some tests in the code to see where the error is:

    Where you connect to the mysql db:

    $db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
    if (!$db) {
        die('Could not connect: ' . mysql_error());
    } else {
    $db_selected = mysql_select_db($mysql_db, $db);
    if (!$db_selected) {
        die ('Can\'t use selected db : ' . mysql_error());
        } 
    }
    

    And where you insert the data in the db:

    $result = mysql_query($qry); 
      if (!$result) {
        die('Could not insert in db: ' . mysql_error());
      }
    

    Now you can find out why the info is not entered in the db by looking into the error.

    Also be sure to add this to the beginning of your php file while developing to display errors on screen:

    <?php
    ini_set('display_errors', 1); error_reporting(E_ALL);  
    

    This will show the errors on screen and report all type of errors, it will ease your coding.

    I hope this is a good start to troubleshoot your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script, that's supposed to match this string: Sometimes, he says
I have this script that works, but I need to change the format of
I have this content script that downloads some binary data using XHR, which is
I have this script and the rows that have td class odd will not
I have this python script which is supposed to wrap all that look like
So I have this function that is supposed make some changes to an image
I have a script that is supposed to trap SIGTERM and SIGTSTP. This is
I have this script that run to fix my menu bar to the browser
I have this script that collects data from users and I want to check
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.