Reputation: 216
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");}
?>
Upvotes: 1
Views: 158
Reputation: 216
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");
}
?>
Upvotes: 1