0

I need to send data to the SQL Server from a HTML form using PHP. The script to open the connection works, but being SQL Server not MySQL it's a bit hard to find a good example to INSERT data into the table.

Tried several methods, but none works. Some examples:

<?php
$query = "
   INSERT INTO dbo.facturi_achizitii 
      (tip, MBxxx, xxx_key, Document, Reference, doc_xxx_text, doc_date, xxx_date, Customer, Business_xxx, xxx_jurnal, valoare_xxx, tax_b_amount, output_xxx) 
   VALUES 
      ('$tip', '$MBxxx', '$xxx_key', '$Document', '$Reference', '$doc_xxx_text', '$doc_date', '$xxx_date', '$Customer', '$Business_xxx', '$xxx_jurnal', '$valoare_xxx', '$tax_b_amount', '$output_xxx')";
$params1 = array($tip, $MBxxx,$xxx_key, $Reference, $doc_xxx_text, $xxx_date, $xxx_date, $Customer, $Business_xxx, $xxx_jurnal, $valoare_xxx, $tax_b_amount, $output_xxx);
$stmt = sqlsrv_query( $conn, $sql, $params);
if( $stmt === false ) {
     die( print_r( sqlsrv_errors(), true));
}
?>

What is wrong with it? Thank you

3
  • 1
    Can you pls post the exact error you are facing? Commented Jun 16, 2022 at 8:49
  • 2
    Though PHP isn't my strong point. that looks like injection to me, not parametrisation. Commented Jun 16, 2022 at 8:54
  • Some issues with your code: 1) You have 14 columns, but only 13 parameter values. 2) You are missing parameters placeholders in your statement. 3| Pass datetime values using unambiguous dattime format. My experience is summarized here. 4) $query and $sql are two different variables (which one do you use). Commented Jun 16, 2022 at 9:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.