sql server - Php-sqlsrv webhook insert data from data array -
i have php script want use data remote server. remote server firing notification , have setup script receive data it. not have experience in sql server.
i can connect server cant seem insert data table.
here code far. code shows how attempting insert data server. got step updating table isn't included. anyways here code
<?php $servername = "asp.net"; $connectioninfo = array( "database"=>"db_a2a8ed_main", "uid"=>"db_a2a8ed_main_admin", "pwd"=>"123456"); $conn = sqlsrv_connect( $servername, $connectioninfo); if( $conn ) { echo "connection established.<br />"; }else{ echo "connection not established.<br />"; die( print_r( sqlsrv_errors(), true)); } $service_name = $_post['service_name']; $business_number = $_post['business_number']; $transaction_reference = $_post['transaction_reference']; $internal_transaction_id = $_post['internal_transaction_id']; $transaction_timestamp = $_post['transaction_timestamp']; $transaction_type = $_post['transaction_type']; $account_number = $_post['account_number']; $sender_phone = $_post['sender_phone']; $first_name = $_post['first_name']; $middle_name = $_post['middle_name']; $last_name = $_post['last_name']; $amount = $_post['amount']; $currency = $_post['currency']; $signature = $_post['signature']; $status = 'unseen'; $params = array($service_name,$business_number,$transaction_reference,$internal_transaction_id,$transaction_timestamp,$transaction_type,$account_number,$sender_phone,$first_name,$middle_name,$last_name,$amount,$currency,$signature,$status); $sql = "insert dbo.mpesa (service_name,business_number,transaction_reference,internal_transaction_id,transaction_timestamp,transaction_type,account_number,sender_phone,first_name,middle_name,last_name,amount,currency,signature,status) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = sqlsrv_query( $conn, $sql, $params); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } ?>
i error
connection established. <br />array ( [0] => array ( [0] => 23000 [sqlstate] => 23000 [1] => 515 [code] => 515 [2] => [microsoft][odbc driver 11 sql server][sql server]cannot insert value null column 'service_name', table 'db_a2a8ed_main.dbo.mpesa'; column not allow nulls. insert fails. [message] => [microsoft][odbc driver 11 sql server][sql server]cannot insert value null column 'service_name', table 'db_a2a8ed_main.dbo.mpesa'; column not allow nulls. insert fails. ) [1] => array ( [0] => 01000 [sqlstate] => 01000 [1] => 3621 [code] => 3621 [2] => [microsoft][odbc driver 11 sql server][sql server]the statement has been terminated. [message] => [microsoft][odbc driver 11 sql server][sql server]the statement has been terminated. ) )
this sql creating table
create table mpesa ( id int identity(1,1) primary key, service_name varchar(400) not null, business_number varchar(400) not null, transaction_reference varchar(400) not null, internal_transaction_id varchar(400) not null, transaction_timestamp varchar(400) not null, transaction_type varchar(400) not null, account_number varchar(400) not null, sender_phone varchar(400) not null, first_name varchar(400) not null, middle_name varchar(400) not null, last_name varchar(400) not null, amount varchar(400) not null, currency varchar(400) not null, signature varchar(400) not null, status varchar(400) not null, balance varchar(400) not null );
Comments
Post a Comment