2

I'm struggling with an output parameter in PHP and SQL Server 2008. I keep getting the error:

Notice: Undefined variable: UserID in C:\inetpub\wwwroot\PersonalWebsitePHP\Register.php on line 67 Error in executing statementArray ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -7 [code] => -7 [2] => An invalid PHP type was specified as an output parameter. DateTime objects, NULL values, and streams cannot be specified as output parameters. [message] => An invalid PHP type was specified as an output parameter. DateTime objects, NULL values, and streams cannot be specified as output parameters. ) )

My code:

$con = sqlsrv_connect(".\SQLExpress", $connectionInfo);
                            if ($con === false) {
                                echo "Could not connect \n";
                                die(print_r(sqlsrv_errors(), true));
                            }

                            $params = array(
                                            array($_POST["FirstName"], SQLSRV_PARAM_IN),
                                            array($_POST["LastName"], SQLSRV_PARAM_IN),
                                            array($_POST["Email"], SQLSRV_PARAM_IN),
                                            array($_POST["Username"], SQLSRV_PARAM_IN),
                                            array(md5($_POST["Password"]), SQLSRV_PARAM_IN),
                                            array(date("Y-m-d H:i:s"), SQLSRV_PARAM_IN),
                                            array($_SERVER["REMOTE_ADDR"], SQLSRV_PARAM_IN),
                                            array("Member", SQLSRV_PARAM_IN),
                                            array("No", SQLSRV_PARAM_IN),
                                            array($UserID, SQLSRV_PARAM_OUT)
                                           );
                            $tsql_callSP = "{call InsertUser(?,?,?,?,?,?,?,?,?,?)}";
                            $stmt3 = sqlsrv_query($con, $tsql_callSP, $params);
                            if ($stmt3 === false) {
                                echo "Error in executing statement";
                                die(print_r(sqlsrv_errors(), true));
                            }
                            sqlsrv_next_result($stmt3);
                            echo "Hi " . $_POST["FirstName"] . ", your User ID is " . $UserID . ".";

                        }
                    } else {
                        die ("The reCAPTCHA wasn't entered correctly.  Go back and try it again.");

                    }

I followed the tutorials exactly. When I declare $UserID before the array, it just prints out the value declared in the variable rather than the output parameter. The input parameters work fine since I can see them in the database. Hope someone can help with this one.

Thank you

Douglas

0

1 Answer 1

2

I am not 100% sure, but I believe this is asking you to assign a type to the output.
Try changing this:

$params = array(
                array($_POST["FirstName"], SQLSRV_PARAM_IN),
                array($_POST["LastName"], SQLSRV_PARAM_IN),
                array($_POST["Email"], SQLSRV_PARAM_IN),
                array($_POST["Username"], SQLSRV_PARAM_IN),
                array(md5($_POST["Password"]), SQLSRV_PARAM_IN),
                array(date("Y-m-d H:i:s"), SQLSRV_PARAM_IN),
                array($_SERVER["REMOTE_ADDR"], SQLSRV_PARAM_IN),
                array("Member", SQLSRV_PARAM_IN),
                array("No", SQLSRV_PARAM_IN),
                array($UserID, SQLSRV_PARAM_OUT)
               );

to

$params = array(
                array($_POST["FirstName"], SQLSRV_PARAM_IN),
                array($_POST["LastName"], SQLSRV_PARAM_IN),
                array($_POST["Email"], SQLSRV_PARAM_IN),
                array($_POST["Username"], SQLSRV_PARAM_IN),
                array(md5($_POST["Password"]), SQLSRV_PARAM_IN),
                array(date("Y-m-d H:i:s"), SQLSRV_PARAM_IN),
                array($_SERVER["REMOTE_ADDR"], SQLSRV_PARAM_IN),
                array("Member", SQLSRV_PARAM_IN),
                array("No", SQLSRV_PARAM_IN),
                array($UserID, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT)
               );

ref from: here

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

Comments

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.