1000 database entires makes my script go dead?

Discussion in 'PHP' started by TedMaster, Oct 30, 2011.

  1. #1
    I finally found the cause of why my PayPal IPN PHP script stopped working. However, I have yet to find the solution.

    I have found out that the script cannot handle a database table with more than approximately 1000 entries(lines), in this case the script is not completed correctly.

    Seeing as my database table now has more than 1000 entries and that cannot really be changed, I need somehow to make the script work regardless. The part of the PHP script where the database is handles has been inserted below.

    Anyone who can find a solution?

    function handleCompleted() {
    	global $LOGFILE, $PRICE, $CURRENCY, $ADMIN_MAIL, $PAYPAL_MAIL,
    			$req,
    			$txn_id, $payer_email, $password, $first_name, $last_name, $address_street, $address_city, $address_state, $address_country,
    			$payment_amount, $payment_currency, $receiver_email;
    
    
    	mysql_connect("dbnameaddress", "dbname", "password") 
    	or logToFile($LOGFILE, "SQL error connecting"); //die(mysql_error());
    	
    	
    	mysql_select_db("dbname") 
    	or logToFile($LOGFILE, "SQL error selecting"); //die(mysql_error());
    	
    	// check that txn_id has not been previously processed
    	$result = mysql_query("SELECT * FROM feast WHERE transaction_id = '".$txn_id."'") or logToFile($LOGFILE, "SQL error querying"); //die(mysql_error());
    	
    	$fail = false;
    	$error = "";
    	if (mysql_num_rows($result) > 0) {
    		$error .= "IPN - duplicate transaction";
    		$fail = true;
    	}
    		
    	// check that receiver_email is your Primary PayPal email
    	if (strcmp($receiver_email, $PAYPAL_MAIL) != 0) {
    		$error .= "IPN - wrong receiver mail:" . $receiver_email. " ";
    		$fail = true;
    	}
    	
    	// check that payment_amount is correct
    	if ( abs($payment_amount - $PRICE) > 0.0001 ) {
    		$error .= "IPN - amount wrong: ". $payment_amount;
    		$fail = true;
    	}
    	
    	// check that payment_currency is correct
    	if (strcmp($payment_currency, $CURRENCY) != 0) {
    		$error .= "IPN - currency wrong";
    		$fail = true;
    	}
    	
    	if ($fail) {
    		logToFile($LOGFILE, $error);
    		mail($ADMIN_MAIL, $error, $req);
    		mysql_close();
    		return;
    	}
    	
    	
    	//payment ok, create entry in database	
    	$password = getRandomString();
    	mysql_query("INSERT INTO feast (transaction_id, email, password, firstname, lastname, street, city, state, country, login) 
    				VALUES('".$txn_id."','".$payer_email."','".$password."','".$first_name."','".$last_name."','"
    				        .$address_street."','".$address_city."','".$address_state."','".$address_country."','0')") or die(mysql_error()); 
    	mysql_close();
    	sendNewUserMail($password);
    }
    PHP:
     
    TedMaster, Oct 30, 2011 IP
  2. TedMaster

    TedMaster Member

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Fix found!

    It was due to an error in the database's primary key. Took my ages to find the solution, but it suddenly appeared before my eyes!
     
    TedMaster, Oct 30, 2011 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #3
    I was going to suggest you look at indexes as well. I'm guessing the primary key was int(3)? I usually make them int(11)
     
    sarahk, Oct 31, 2011 IP
  4. WPC

    WPC Peon

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I would of suggested it would of been a 'MySQL' problem myself as well, seeing as the code looks right.
     
    WPC, Oct 31, 2011 IP