2016-06-12 117 views
0

此代碼從數據庫獲取值並形成一個sms模板,然後將該moble編號和消息傳遞給webservice以發送短信。這是一個功能牆()的一部分.....PHP Mysql從函數插入語句

 $name = $resultarr['name']; 
    $amount = $resultarr['amount']; 
    $transaction_id = $resultarr['trans_id']; 
    $date = $resultarr['time_paid']; 

    //message template 
    $message = "Dear $name we have received $amount from you. MPESA transaction Id $transaction_id on $date."; 

    $mobilenumber = $resultarr['msisdn']; // get mobile number from array 
    $message_sent = $message; 

    $serviceArguments = array(
      "mobilenumber" => $mobilenumber, 
      "message" => $message_sent 
    ); 

    $client = new SoapClient("http://59.38.606.10:8080/smsengine/smsws?WSDL"); 

    $result = $client->process($serviceArguments); 

grabdetails($message_sent, $mobilenumber); 

    return $result; 

} 
//I call the function wall() to send sms   

    wall(); 

    $perm = wall(); 
    $status = $sperm->return; //outputing the status 
    // Here I want to capture the $status variable and put it in a db below 
    echo "$status"; 


function grabdetails($messagee, $mobno) 
{ 

$message_sent = $messagee; 
$mobilenumber = $mobno; 


$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "smsdb"; 

    // Create connection 


    // Check connection 

    $sql = "INSERT INTO smsdb (sms_text, receiver_number, time_sent, status) 
     VALUES 
     ('$message_sent', '$mobilenumber', NOW(), $status)"; 

的問題是我怎麼搶$狀態IND它在功能插入到數據庫,因爲它不是?請。幫助,任何人?

+1

問題到底是什麼?當你有「狀態」值時,用該值執行一條「INSERT」語句。您可以直接在獲取該值的位置後面的行中執行該操作,或者編寫函數來完成該操作,並在獲取該值後調用該函數。目前尚不清楚問題是什麼。 – David

+0

你好@大衛,所以你說我可以插入$狀態在我回應它的確切點?這是$ sql =「INSERT INTO smsdb(status) VALUES ('$ status')」;有必要我可以插入其他變量? –

回答

0

上面的代碼是不完整的,但我認爲頂部的功能$client = new SoapClient("http://59.38.606.10:8080/smsengine/smsws?WSDL");實際上是牆功能。如果是這樣,那麼該函數返回什麼,即$result實際上具有您需要的狀態。因此,通過這段代碼片段(假設$ sperm是一個錯字,實際上應該是$ perm,來自wall函數的響應),您可以從wall()得到響應,它是一個對象並具有您需要的狀態。

$perm = wall(); 
$status = $sperm->return; //outputing the status 
// Here I want to capture the $status variable and put it in a db below 
echo "$status"; 

如果這是正確的,然後在牆上函數調用grabdetails之前,你確實有狀態,你可以將它發送給函數是這樣的:

grabdetails($message_sent, $mobilenumber, $result->return); 

,然後更改的定義grabdetails以接收狀態並在DB插入中使用它。

+0

感謝您的指導,讓我試試看。將更新出來。 @trajchevska –