简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM