Reputation: 1
I am using Sql server 2012 procedure to execute using php and the result should be store into table on sql server only. I am facing this issue, I can fetch the data from php code but when i insert that data into table only one value is inserted.I can see different values on my screen when i run php script.but back to data base only first value is inserted. I am not getting where i am going wrong. please help me with this. Thanks in advance.
while ($obj = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
{
if($obj['Bank_Name']!= $obj['Bank_Name_old'])
{
$obj['company_code'];
$obj['Account_Code'];
$obj['Bank_Name'];
$obj['Bank_Name_old'];
$obj['field_name']='Bank Name';
if($obj['field_name']='Bank Name')
{
$old=$obj['Bank_Name_old'];
$new=$obj['Bank_Name'];
}
$query="insert into vns_db.dbo.client_details_log (company_code,client_id,field_name,original_value,new_value) values ('".$obj['company_code']."',
'".$obj['Account_Code']."','".$obj['field_name']."','$old','$new')".'<br>';
$res = sqlsrv_query($conn,$query);
echo $res;
echo $query;
}
this is php script output
Upvotes: 0
Views: 135
Reputation: 17797
Remove the .'<br>'
from your query. It's a HTML line break, SQL can't handle it.
You can always use sqlsrv_errors()
to check for errors if a query doesn't work as intended:
$res = sqlsrv_query($conn,$query);
if ( $res === false ) {
echo "Error in SQL query:";
var_dump( sqlsrv_errors() );
}
Upvotes: 1