Mysql / PHP错误:不显示$ username

时间:2014-01-03 22:03:21

标签: php mysql paypal mysqli

Hello Everyone我发现我的php SQL没有更新表“as_users”的问题是因为它无法获取$username

问题是我不知道如何检测$username,它已经检测到它并将其显示为html但是当它试图执行mysql时它无法获取$username我不知道为什么,任何人都可以解释或帮助我解决这个问题吗?我将不胜感激。

更多信息:电子邮件不会$username mysql,但底部的回显显示正确的用户名。

<?php
//
//  
//  
//  IPN system $username cannot be found in mysqli/emails but can be in html
//
//
// The way to inform the user about the status of your payment

require_once "paypal_config.php";
include 'templates/header.php';
$userDetails = $user->getDetails();
$user = $db->select("SELECT * FROM `as_users`");
$username =$userInfo['username'];

//
// FUNCTIONS
//
// Basic function for email notification 
function send_mail($message,$email)
{
    $subject=   "New Payment";
    $sender=    "Paypal Payment $company";

    $header .=  "MIME-Version: 1.0\n"; 
    $header .=  "Content-type: text/html; charset=utf-8\n"; 
    $header .=  "From: ".$sender."<".$email.">\n";
    $header .=  "Return-path: ". $refers."\n";
    $header .=  "X-Mailer: PHP/". phpversion()."\n";
    $message .= "<br>";

    foreach($_POST as $name=>$value)
            {
            $message .= $name.": ".$value."<br>";
            }

    mail($email, $subject, $message, $header); 

}


// Examines all the IPN and turns it into a string
function Array2Str($kvsep, $entrysep, $a)
{
    $str = "";
    foreach ($a as $k=>$v)
    {$str .= "{$k}{$kvsep}{$v}{$entrysep}";}
    return $str;
}


//
// Verifying paypal message - Using POST vars rm=2 in html form 
//
$req = 'cmd=_notify-validate';
$fullipnA = array();

foreach ($_POST as $key => $value)
{
    $fullipnA[$key] = $value; 
    $encodedvalue = urlencode(stripslashes($value));
    $req .= "&$key=$encodedvalue";
}
$fullipn = Array2Str(" : ", "\n", $fullipnA);

    $url ='https://www.paypal.com/cgi-bin/webscr';  

$curl_result=$curl_err='';
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL,$url);
curl_setopt($fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $req);
curl_setopt($fp, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($fp, CURLOPT_HEADER , 0); 
curl_setopt($fp, CURLOPT_VERBOSE, 1);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($fp, CURLOPT_TIMEOUT, 30);

$response = curl_exec($fp);
$curl_err = curl_error($fp);
curl_close($fp);


// Vars received by Paypal
$payment_status = $_POST['payment_status'];
if (strcmp ($response, "VERIFIED") == 0)        
{
    // Check the status of the order
    if ($payment_status != "Completed")
    {       
        send_mail("The payment was not accepted by paypal - Payment Status: $payment_status", $email);

        exit;
    }
    // all good so far, the transaction has been confirmed so I can do all -> Update DB, stock, credit computations, activate accounts etc etc

    // Vars received by Paypal
    $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'];
    $txn_type = $_POST['txn_type'];
    $pending_reason = $_POST['pending_reason'];
    $payment_type = $_POST['payment_type'];
    $custom = $_POST['custom'];
    $invoice =$_POST['invoice'];
    // Buyer information
    $first_name=$_POST['first_name'];
    $last_name=$_POST['last_name'];
    $address_name=$_POST['address_name'];
    $address_country=$_POST['address_country'];
    $address_country_code=$_POST['address_country_code'];
    $address_zip=$_POST['address_zip'];
    $address_state=$_POST['address_state'];
    $address_city=$_POST['address_city'];
    $address_street=$_POST['address_street'];
    if ($paypal_mysql) {
    $mysqli = new mysqli('****', '**', '***', '**');
    $stmt = $mysqli->prepare("UPDATE `as_users` SET paid='1', reg_date=CURRENT_TIMESTAMP, end_date=DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL 30 DAY) WHERE username = ?");
    $stmt->bind_param('s', $username);
    $stmt->execute();
        send_mail("Tried to SQL  table with: $username", $email);
    }
    send_mail("New payment was successfully recieved from $payer_email username: $username1", $email);
  }else{    
     //the transaction is invalid I can NOT charge the client. 
     send_mail("$username Invalid payment - $fullipn", $email);

}
?>
<li>User: <?php echo $username ?> </li>

1 个答案:

答案 0 :(得分:0)

这里有无效的变量名称$username1(我想它应该是$username):

send_mail("New payment was successfully recieved from $payer_email username: $username1", $email);

还不清楚$paypal_mysql的来源。我想如果没有设置,那么你会错过你的保存代码。