3

您好,我在运行脚本时遇到了一些麻烦,我不断收到一条错误消息,说它需要两个参数,我不知道如何修复它,脚本如下:

<?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 个参数,1 个在第 27 行的 file_name.php 中给出

第 27 行是我更新客户的地方。如果有人能在脚本中发现错误,您能否告诉我,是的,我还没有完成 SQL 注入,在这个阶段我只是想在实现它之前让它工作。

感谢大家的帮助,非常感谢

4

1 回答 1

2

尝试将连接传递给 sqlsrv_query

就像是:

 $querychange = sqlsrv_query($conn, "UPDATE customers SET userPass='$newpassword' WHERE userName='$username'");
于 2013-05-12T13:15:57.667 回答