0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

I'm not sure I understand where 'array' comes into place here. I just need these two actions to work when the form is submitted. Sorry, I'm kind of new to this.
the functions expects 2 parameters that are $conn , and $sql ; and optionally an array of parameters. what you gave is $conn, $sql1, $sql2. this is why you have the error message : An invalid parameter was passed to sqlsrv_query
why dont you do 2 queries : $stmt1 = sqlsrv_query( $conn, $tsql1); $stmt2 = sqlsrv_query( $conn, $tsql2);
Ok that seemed to work. Now I'm just getting a 'COUNT field incorrect or syntax error' on the 2nd part....nevermind I see what I did wrong, I need to add params, etc.
Look your "?" number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.