YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Not sure why this isn't writing to MySQL db Options
myrtusugni
#1 Posted : Wednesday, April 30, 2003 7:47:18 AM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 5
Location: ,
I was thinking I got through this implementation when I stopped getting errors on my return page, but nothing is writing to the MySQL db. If anyone can help me figure this out I would be very grateful. This is the code on my IPN.php: <?php // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($HTTP_POST_VARS as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $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); // assign posted variables to local variables // note: additional IPN variables also available -- see IPN documentation $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $quantity1 = $_POST['quantity1']; $item_name1 = $_POST['item_name1']; $item_number1 = $_POST['item_number1']; $quantity2 = $_POST['quantity2']; $item_name2 = $_POST['item_name2']; $item_number2 = $_POST['item_number2']; $quantity3 = $_POST['quantity3']; $item_name3 = $_POST['item_name3']; $item_number3 = $_POST['item_number3']; $quantity4 = $_POST['quantity4']; $item_name4 = $_POST['item_name4']; $item_number4 = $_POST['item_number4']; $quantity5 = $_POST['quantity5']; $item_name5 = $_POST['item_name5']; $item_number5 = $_POST['item_number5']; $quantity6 = $_POST['quantity6']; $item_name6 = $_POST['item_name6']; $item_number6 = $_POST['item_number6']; $quantity7 = $_POST['quantity7']; $item_name7 = $_POST['item_name7']; $item_number7 = $_POST['item_number7']; $quantity8 = $_POST['quantity8']; $item_name8 = $_POST['item_name8']; $item_number8 = $_POST['item_number8']; $quantity9 = $_POST['quantity9']; $item_name9 = $_POST['item_name9']; $item_number9 = $_POST['item_number9']; $quantity10 = $_POST['quantity10']; $item_name10 = $_POST['item_name10']; $item_number10 = $_POST['item_number10']; $quantity11 = $_POST['quantity11']; $item_name11 = $_POST['item_name11']; $item_number11 = $_POST['item_number11']; $quantity12 = $_POST['quantity12']; $item_name12 = $_POST['item_name12']; $item_number12 = $_POST['item_number12']; $payment_status = $_POST['payment_status']; $payment_gross = $_POST['payment_gross']; $payer_email = $_POST['payer_email']; $quantity = $_POST['quantity']; $payment_date = $_POST['payment_date']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $address_street = $_POST['address_street']; $address_city = $_POST['address_city']; $address_state = $_POST['address_state']; $address_zip = $_POST['address_zip']; $order_num = $_POST['txn_id']; if (!$fp) { // ERROR echo "$errstr ($errno)"; } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed // if (!strcmp ($payment_status, "Completed")) { // // check that txn_id has not been previously processed // $dbh = mysql_connect('localhost','*********','***********') or die ('I cannot connect to the database because: ' . mysql_error()); // $txn_check = mysql_query("SELECT txn_id FROM $orders WHERE txn_id = '$txn_id'"); // $txn_exist = mysql_num_rows(($txn_check),$db); // if ($txn_exist) { // $url = "http://www.****.com/index.htm" // header('Location: ' . $url); // } else { // check that receiver_email is your Primary PayPal email // if (!strcmp ($receiver_email, "****@******.com")) { // process payment $dbh = mysql_connect('localhost',**********','*************') or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db('***********'); $resultat_sql = mysql_query("INSERT INTO `orders` ( `txn_id` , `quantity1` , `item_name1` , `item_number1` , `quantity2` , `item_name2` , `item_number2` , `quantity3` , `item_name3` , `item_number3` , `quantity4` , `item_name4` , `item_number4` , `quantity5` , `item_name5` , `item_number5` , `quantity6` , `item_name6` , `item_number6` , `quantity7` , `item_name7` , `item_number7` , `quantity8` , `item_name8` , `item_number8` , `quantity9` , `item_name9` , `item_number9` , `quantity10` , `item_name10` , `item_number10` , `quantity11` , `item_name11` , `item_number11` , `quantity12` , `item_name12` , `item_number12` , `payment_status` , `payment_gross` , `payer_email` , `payment_date` , `first_name` , `last_name` , `address_street` , `address_city` , `address_state` , `address_zip` ) VALUES ( `$txn_id` , `$quantity1` , `$item_name1` , `$item_number1` , `$quantity2` , `$item_name2` , `$item_number2` , `$quantity3` , `$item_name3` , `$item_number3` , `$quantity4` , `$item_name4` , `$item_number4` , `$quantity5` , `$item_name5` , `$item_number5` , `$quantity6` , `$item_name6` , `$item_number6` , `$quantity7` , `$item_name7` , `$item_number7` , `$quantity8` , `$item_name8` , `$item_number8` , `$quantity9` , `$item_name9` , `$item_number9` , `$quantity10` , `$item_name10` , `$item_number10` , `$quantity11` , `$item_name11` , `$item_number11` , `$quantity12` , `$item_name12` , `$item_number12` , `$payment_status` , `$payment_gross` , `$payer_email` , `$payment_date` , `$first_name` , `$last_name` , `$address_street` , `$address_city` , `$address_state` , `$address_zip` )",$dbh); // } // } // } } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } } fclose ($fp); } ?> Thanks, Jeremy
Sponsor  
 
hockey4all
#2 Posted : Wednesday, April 30, 2003 12:54:29 PM
Rank: Starting Member

Groups: Registered

Joined: 2/12/2003
Posts: 6
Location: ,
You may need to use the AddSlashes function in php in your :
addslashes(mysql_query("query you have"));

Don't forget to put that second bracket at the end ).

Let me know.
myrtusugni
#3 Posted : Wednesday, April 30, 2003 1:22:05 PM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 5
Location: ,
Thanks for the quick response

But no luck.
If you think of anything else let me know.

Thanks alot,

Jeremy
iPop
#4 Posted : Wednesday, April 30, 2003 2:11:33 PM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 4
Location: ,
Try this to avoid any errors in Db field names and the POSTED variable values.

It will basically compile ONLY the POSTED IPN variables and insert them into the Db, as long as your Db fields are the same name as the POSTED variable names.

// add all Posted IPN variables and values to field_names and value_names variables
// separate with comma
while( @list($key,$value) = @each($_POST) ) {
$field_names .= $key . ", ";
$value_names .= "'" . $value . "', ";
}

// subtract the last comma from field_names
$field_names = substr($field_names, 0, (strlen($field_names)-2));

// subtract the last comma/space from value_names
$value_names = substr($value_names, 0, (strlen($value_names)-2));

// insert into Db using feild_names and value_names variables
$query = "INSERT INTO orders ($field_names) VALUES ($value_names)";

Hope this helps
iPop

Form - Colour - Style - Pop
myrtusugni
#5 Posted : Wednesday, April 30, 2003 2:27:22 PM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 5
Location: ,
For fear of sounding completely ignorant, I hesitate in asking, but I am ignorant. How do I implement the:

// insert into Db using feild_names and value_names variables
$query = "INSERT INTO orders ($field_names) VALUES ($value_names)";

Thanks ahead of time,

Jeremy
iPop
#6 Posted : Wednesday, April 30, 2003 2:35:53 PM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 4
Location: ,
Sorry, I forgot the rest of the PHP code to execute the $query and check if it worked.

// insert into Db using feild_names and value_names variables
$query = "INSERT INTO orders ($field_names) VALUES ($value_names)";

// assign and execute $query
$result = @mysql_query($query);

// check if there was an error
if (!$result) {
echo "error";
exit;
}

// if no error then inform it worked and close Db connection
echo "Inserted to Db";
mysql_close( $dbh );

iPop

Form - Colour - Style - Pop
myrtusugni
#7 Posted : Wednesday, April 30, 2003 2:44:23 PM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 5
Location: ,
Am I correct in assuming that that code should replace my $resultat_sql = ... line? Everything else stays the same? I hope I am wrong because it did not work like that.

Jeremy
myrtusugni
#8 Posted : Wednesday, April 30, 2003 5:39:50 PM
Rank: Starting Member

Groups: Registered

Joined: 4/30/2003
Posts: 5
Location: ,
Thanks for all your help, I found the problem . . . extra ")"

jeremy
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFVision Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.320 seconds.