2016-06-12 116 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 –