0

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

enter image description here

1
  • remove .'<br>' from $query variable Commented Jan 20, 2016 at 5:35

1 Answer 1

1

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() );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.