Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ipn.php ไม่ยอม insert เข้า database ช่วยดูโค๊ดให้หน่อยค่ะ



 

ipn.php ไม่ยอม insert เข้า database ช่วยดูโค๊ดให้หน่อยค่ะ

 



Topic : 080415



โพสกระทู้ ( 417 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<?PHP
/**                                                              
 *                                                                
 *                                                               
 *                                                     
 */
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST 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";

// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


// assign posted variables to local variables
$item_name = $_POST['item_name'];
$business = $_POST['business'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$mc_gross = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$quantity = $_POST['quantity'];
$num_cart_items = $_POST['num_cart_items'];
$payment_date = $_POST['payment_date'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];
$settle_amount = $_POST['settle_amount'];
$memo = $_POST['memo'];
$payer_email = $_POST['payer_email'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$item_number = $_POST['item_number'];
$tax = $_POST['tax'];
$option_name1 = $_POST['option_name1'];
$option_selection1 = $_POST['option_selection1'];
$option_name2 = $_POST['option_name2'];
$option_selection2 = $_POST['option_selection2'];
$for_auction = $_POST['for_auction'];
$invoice = $_POST['invoice'];
$custom = $_POST['custom'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_business_name = $_POST['payer_business_name'];
$payer_id =$_POST['payer_id'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = $_POST['mc_fee'];
$exchange_rate = $_POST['exchange_rate'];
$settle_currency  = $_POST['settle_currency'];
$parent_txn_id  = $_POST['parent_txn_id'];
$pending_reason = $_POST['pending_reason'];
$reason_code = $_POST['reason_code'];
$os1 = $_POST['os1'];
$on0 = $_POST['on0'];
$on1 = $_POST['on1'];
$os0 = $_POST['os0'];
include("header.php");
$result = mysql_query("SELECT * FROM sitesettings");
while($row = mysql_fetch_array($result))
{
$domain = mysql_real_escape_string($row["domain"]);
$siteurl = mysql_real_escape_string($row["site_url"]);
}
//DB connect creds and email
$notify_email =  "";         //email address to which debug emails are sent to
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$fecha = date("j, n, Y");
//check if transaction ID has been processed before
$checkquery = "select txnid from paypal_payment_info where txnid='".$txn_id."'";
$sihay = mysql_query($checkquery) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$nm = mysql_num_rows($sihay);
if ($nm == 0){
//execute query
     if ($txn_type == "cart"){
     for ($i = 1; $i <= $num_cart_items; $i++) {
         $itemname = "item_name".$i;
         $itemnumber = "item_number".$i;
         $on0 = "option_name1_".$i;
         $os0 = "option_selection1_".$i;
         $on1 = "option_name2_".$i;
         $os1 = "option_selection2_".$i;
         $quantity = "quantity".$i;
         $struery = "insert into paypal_payment_info(firstname,lastname,txnid,mc_gross,paymentstatus,tax,itemnumber,itemname,seller_username,postdate,buyer_username,quantity) values ('".$first_name."','".$last_name."','".$txn_id."','".$mc_gross."','".$payment_status."','".$tax."','".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on0]."','".$fecha."','".$_POST[$on1]."','".$_POST[$quantity]."')";
         $result = mysql_query($struery) or die("Cart - paypal_cart_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
         $strQuery = "insert into jobs_bought(job_id,willdo,username,seller_username,feedback_left,date,payment_confirmed) values ('".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on1]."','".$_POST[$on0]."','no','".$fecha."','no')";
         $result = mysql_query("insert into jobs_bought(job_id,willdo,username,seller_username,feedback_left,date,payment_confirmed) values ('".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on1]."','".$_POST[$on0]."','no','".$fecha."','no')") or die(" Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
         $strQuery = "insert into jobs_sold(job_id,willdo,username,buyer_username,feedback_left,date,payment_confirmed) values ('".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on0]."','".$_POST[$on1]."','no','".$fecha."','no')";
         $result = mysql_query("insert into jobs_sold(job_id,willdo,username,buyer_username,feedback_left,date,payment_confirmed) values ('".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on0]."','".$_POST[$on1]."','no','".$fecha."','no')") or die(" Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());

         mysql_query("UPDATE jobs SET times_bought=times_bought+1 where id='".mysql_real_escape_string($_POST[$itemnumber])."'") or die(mysql_error());
         $job = mysql_real_escape_string($_POST[$itemname]);
$job = stripslashes(nl2br($job));
$time = date('r');
$to      = $custom;
$subject = "".$lang["PP_SUBJECT"].": ".$job."";
$message = "Hi! $_POST[$on0]\n Your job: $job ".$lang["PP_EMAIL1"]." $_POST[$on1] on $time\n".$lang["PP_EMAIL2"].".\n".$lang["PP_EMAIL3"]."\n
The $domain team.";
$headers = 'From: noreply@'.$domain.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

$subject = ''.$lang["PP_SUBJECT"].': '.$job.'';
$message =  'Your job: '.$job.' '.$lang["PP_EMAIL1"].' '.$_POST[$on1].'';
$filename = 'none';
$filepath = 'none';
$message_read = 'no';
$query = sprintf("INSERT INTO messages_all (receiver_id, sender_id,subject,message,date)
            VALUES('%s', '%s', '%s', '%s', '%s')",
            mysql_real_escape_string($_POST[$on0]),
            mysql_real_escape_string($_POST[$on1]),
            mysql_real_escape_string($subject),
            mysql_real_escape_string($message),
            mysql_real_escape_string($fecha));
            // run the query
    if(!mysql_query($query))
            {
            echo 'Query failed '.mysql_error();
            exit();
            }
$query = sprintf("INSERT INTO messages_received (sender_id,receiver_id, subject,message,filename,filepath,date,message_read)
            VALUES( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
            mysql_real_escape_string($_POST[$on1]),
            mysql_real_escape_string($_POST[$on0]),
            mysql_real_escape_string($subject),
            mysql_real_escape_string($message),
            mysql_real_escape_string($filename),
            mysql_real_escape_string($filepath),
            mysql_real_escape_string($fecha),
            mysql_real_escape_string($message_read));
            // run the query
    if(!mysql_query($query))
            {
            echo 'Query failed '.mysql_error();
            exit();
            }
$query = sprintf("INSERT INTO messages_sent (receiver_id, sender_id,subject,message,date)
            VALUES( '%s', '%s', '%s', '%s', '%s')",
            mysql_real_escape_string($_POST[$on0]),
            mysql_real_escape_string($_POST[$on1]),
            mysql_real_escape_string($subject),
            mysql_real_escape_string($message),
            mysql_real_escape_string($fecha));
            // run the query
    if(!mysql_query($query))
            {
            echo 'Query failed '.mysql_error();
            exit();
            }
if(!mysql_query)
            {
            echo 'Query failed '.mysql_error();
            exit();
            }
}
}
// send an email in any case
 echo "Verified";
     mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n  $strQuery2");
}
else {
// send an email
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req \n $strQuery\n $struery\n  $strQuery2");
}
}
// if the IPN POST was 'INVALID'...do this
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
mail($notify_email, "INVALID IPN", "$res\n $req");
}
}
fclose ($fp);
}
?>




Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-06-29 21:43:24 By : dferru View : 1194 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code เยอะน่ะครับ ว่าแต่มี Error หรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-30 14:54:23 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ipn.php ไม่ยอม insert เข้า database ช่วยดูโค๊ดให้หน่อยค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่