Im using this tutorial: http://www.rune-server.org/runescape...items-new.html

MY IPN script code:

Code:
<?php
if ($_REQUEST['debug']) {
ini_set("display_errors", True);
error_reporting(E_ALL);
}
$mysql_host = '****'; //Leave at localhost  
$mysql_user = '****'; //DB User  
$mysql_pass = '***'; //DB Pass  
$mysql_db = '****'; //DB Name  
$file = 'paypal.log'; //Paypal Log Name will be placed in the same location as your ipn.php file 
$payer_email = $_REQUEST['payer_email']; 
$ip = $_SERVER['REMOTE_ADDR'];
$time = date("F j, Y, g:i a"); 
$paylist = array("14.99" => 666, "5.00" => 5000, "10.00" => 10000, "15.00" => 15500, "20.00" => 21000, "25.00" => 27000, "50.00" => 55000);

// connect db  

$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);

$custom = stripslashes(ucwords(strtolower(trim($_REQUEST['custom']))));  
$receiver_email = $_REQUEST['receiver_email'];  
$payment_status = $_REQUEST['payment_status'];  
$mc_gross = $_REQUEST['mc_gross']; 
mysql_select_db($mysql_db, $db);  
if ($_REQUEST['debug']){
print $payment_status . '\n';
print (isset($paylist[$mc_gross])) ? 1 : 0 . '\n';
print $receiver_email . '\n';
print $custom . '\n';
}
if ($payment_status == "Completed" && $receiver_email == "***" && isset($paylist[$mc_gross])) {  

$query = "SELECT item FROM accounts WHERE accounts.name = '$custom'";  

$result = mysql_query($query);  

$prem = mysql_fetch_array($result);  
$somecode = "'$time' '$custom' '$payer_email' '$mc_gross' '$ip'\r\n";

// figure out how much to give
$give = $paylist[$mc_gross];
$itemid = $prem['item'] + $give;  
// $points = mysql_query($prem)  
$qry2 = "UPDATE accounts SET item = '$itemid' WHERE accounts.name = '$custom'";  
// Log Paypal Transaction 
$hak = fopen($file, "a"); 
fwrite($hak, $somecode); 
fclose($hak); 

$result2 = mysql_query($qry2);  
}  
else  
 {   
 echo("Error.");  
 }  
?>

MY MYSQL DATABASE:
Code:
CREATE TABLE `status` (
	`id` INT(10) NOT NULL AUTO_INCREMENT,
	`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`username` VARCHAR(15) NULL,
	`item` SMALLINT(5) NULL,
	`quantity` SMALLINT(5) NULL,
	`given` TINYINT(1) NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`)
)
Paying works fine, and it redirects back to my site perfectly.
But the MYSQL isn't added into my databse, and yes my sql connection is working and the database's are set-up perfectly.
The error is with the IPN script.. can someone help me please?

i GET THIS error:

[18-Oct-2011 14:45:47] PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/newrunen/public_html/paypal/ipn/ipn.php on line 37


Thanks!