1

I am trying to execute following query, but it provides a syntax error which i couldn't find. Appreciate your help to resolve the issue.

Error

Array ( [0] => Array ( [0] => 07002 [SQLSTATE] => 07002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error [message] => [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error ) )

<?php

session_start();
require_once '../../../config/dbconfig.php';

$sql = "EXEC    smeProBizInspecInsert
@strLeadRefNo   =  ? ,
@strCustName =  ? ,                 
@strEnteredBy  =  ? , 
@dtmEnteredDate =  '',
@strInspectStatus = 'SMS06',
@strBranch = ? ";

$stmt=sqlsrv_prepare($conn,$sql,array(&$_POST['strLeadRefNo'],&$_POST['customerName'],&$_SESSION['NAME'], &$_SESSION['BRANCH'])); 
sqlsrv_execute($stmt);

$stmt = sqlsrv_prepare($conn, $sql);
if (!sqlsrv_execute($stmt)) {die( print_r( sqlsrv_errors(), true) );}
else {echo json_encode("success");} 

?>
4
  • Do all POST/SESSION arrays have value? Plus, why are you adding & to them? Is that something in a query as such that I don't know about? Far as I remember, single ampersands are bitwise characters. Commented Feb 15, 2020 at 16:28
  • Thank you for your comment, i followed the instructions in php.net/manual/en/function.sqlsrv-prepare.php.. Thats why i put an &sign. And all post and Sessions have values. Commented Feb 15, 2020 at 16:31
  • 1
    You're right, my bad, sorry. Well I am not the guy for this question. It appears that you're using stored procedures so I added that tag to the question. I hope someone who knows will be able to help you. Commented Feb 15, 2020 at 16:35
  • 1
    Any way thank you very much for commenting out for this post. The boost given by you will help to get an answer. Commented Feb 15, 2020 at 16:37

1 Answer 1

1

The issue was resolved, when i passed @dtmEnteredDate and @strInspectStatus through variables. Also i have mistakenly kept the following, which caused the error.

sqlsrv_execute($stmt); $stmt = sqlsrv_prepare($conn, $sql);

<?php

session_start();
require_once '../../../config/dbconfig.php';


$sql = "EXEC    smeProBizInspecInsert
@strLeadRefNo   =  ? ,
@strCustName =  ? ,                 
@strEnteredBy  =  ? , 
@dtmEnteredDate =  ? ,
@strInspectStatus = ?,
@strBranch = ? ";

$edate = '';
$status = 'SMS06';

$stmt=sqlsrv_prepare($conn,$sql,array(&$_POST['strLeadRefNo'],&$_POST['customerName'],&$_SESSION['NAME'], 
&$edate, &$status ,&$_SESSION['BRANCH'])); 

if (!sqlsrv_execute($stmt)) {

  die( print_r( sqlsrv_errors(), true) );


}


else 
{

  echo json_encode("success");

} 


?>
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.