您好,我在运行脚本时遇到了一些麻烦,我不断收到一条错误消息,说它需要两个参数,并且我不知道如何解决它,这里是脚本:
<?php session_start (); if(isset($_SESSION['user'])){ $username = $_SESSION['username']; if(isset($_POST['submit'])){ $oldpassword = $_POST['oldpassword']; $newpassword = $_POST['newpassword']; $serverName = "server"; $connectionInfo = array("Database"=>"database","UID"=>"id", "PWD"=>"pass"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false){ echo "Error in connection.\n"; die( print_r( sqlsrv_errors(), true)); } $tsql = "SELECT userPass FROM customers WHERE userName='$username'"; $stmt = sqlsrv_query($conn, $tsql, array(), array( "Scrollable" => 'static' )); if ( !$stmt ){ die( print_r( sqlsrv_errors(), true)); } $rows = sqlsrv_num_rows($stmt); if($rows === false){ die( print_r( sqlsrv_errors(), true)); }elseif($rows == 0){ echo "No rows returned."; exit(); }else{ $querychange = sqlsrv_query("UPDATE customers SET userPass='$newpassword' WHERE userName='$username'"); session_destroy(); die ("Your password has been changed. <a href='index.php'>Return</a> to the main page and login with your new password."); } } } ?>
我不断收到这个错误
PHP警告:sqlsrv_query()至少需要2个参数,第27行的file_name.php中给出1个
第27行是我更新客户的地方。如果有人能在脚本中发现错误,您能告诉我吗,是的,我还没有完成SQL注入,在这个阶段,我只是想在实现之前使其正常工作。
感谢您提供的所有帮助,不胜感激
尝试将连接传递到sqlsrv_query
就像是:
$querychange = sqlsrv_query($conn, "UPDATE customers SET userPass='$newpassword' WHERE userName='$username'");