Alex_TCD Alex_TCD - 2 months ago 11
PHP Question

Adding a second variable into an SQL query using PHP

I want to add a second action to the database but when I added in the $tsql2, I get an "An invalid parameter was passed to sqlsrv_query":

$tsql = "UPDATE dbo.mspClient SET avdesktopProduct='".$_POST['product']."',
avdesktopProvider='".$_POST['provider']."',
avdesktopRate='".$_POST['rate']."',
avdesktopQty='".$_POST['qty']."',
avdesktopDate=getdate()

WHERE client='".$_POST['client']."'";

$tsql2 = "INSERT INTO dbo.mspArchive SET client='".$_POST['client']."',
avdesktopchangerate='".$_POST['rate']."',
avdesktopchangeqty='".$_POST['qty']."',
avdesktopchangeDate=getdate()

VALUES (?,?,?,?)";

$stmt = sqlsrv_query( $conn, $tsql, $tsql2);


Any help would be appreciated...it's probably something simple. The $tsql works just fine; this happened when I added in $tsql2.

Answer

http://php.net/manual/fr/function.sqlsrv-query.php

sqlsrv_query ( resource $conn , string $sql [, array $params [, array $options ]] )

You are trying to give two requests instead of one with parameters...

For statements that you plan to execute only once, use sqlsrv_query(). If you intend to re-execute a statement with different parameter values, use the combination of sqlsrv_prepare() and sqlsrv_execute().

Comments