Tilan04
Tilan04

Reputation: 86

COUNT field incorrect or syntax error inside of PHP

I'm developing changes to the data in a table once a button is clicked on a web but the next error comes out:

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

)

I've reviewed the code for a few hours but I haven't found the typo. This is the code:

<?php
ini_set('max_execution_time', 300);
$serverName = "serverName\SQLEXPRESS";
$connectionInfo = array( "Database"=>"dataBase", "UID"=>"user", "PWD"=>"pass");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn === false ) {                                  
die( print_r( sqlsrv_errors(), true));
}

$sql1 = "DECLARE @a INT ". PHP_EOL;
$sql1 .= "SELECT @a = condLot FROM productos WHERE prodID = ? ". PHP_EOL;
$sql1 .= "IF (@a > 0) ". PHP_EOL;
$sql1 .= "UPDATE productos SET estadoAl = (estadoAl + 1), condLot = (condLot - 1) FROM productos WHERE prodID = ? ". PHP_EOL;
$sql1 .= "ELSE ". PHP_EOL;
$sql1 .= "UPDATE productos SET estadoAl = (estadoAl + 1) FROM productos WHERE prodID = ? ". PHP_EOL;
$var = array($_GET["idProd"]);


$stmt1 = sqlsrv_query( $conn, $sql1, $var);
if( $stmt1 === false ) {
    die( print_r( sqlsrv_errors(), true));
}

Upvotes: 1

Views: 3215

Answers (1)

Nandan Bhat
Nandan Bhat

Reputation: 1563

Update queries don't have from clause. Try the following code.

$sql1 .= "UPDATE productos SET estadoAl = (estadoAl + 1), condLot = (condLot - 1) WHERE prodID = ? ". PHP_EOL;

Upvotes: 4

Related Questions