Alex_TCD Alex_TCD - 1 year ago 74
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']."',

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

$tsql2 = "INSERT INTO dbo.mspArchive SET client='".$_POST['client']."',

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

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

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

Answer Source

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().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download