zoro724
zoro724

Reputation: 87

update user details, sql server 2008 sqlsrv

Hello i am having some trouble getting a script to run, i keep getting an error message saying it expects two parameters and i have no idea how to fix it, heres the script:

<?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.");
    }
}
}
?>

I keep getting this error

PHP Warning: sqlsrv_query() expects at least 2 parameters, 1 given in file_name.php on line 27

Line 27 is where i update customers. If anyone can spot an error in the script can you let me know, also yes I've not done SQL injection, at this stage I'm simply trying to get it working before I implement that.

Thanks for all the help, it's much appreciated

Upvotes: 3

Views: 3254

Answers (1)

elrado
elrado

Reputation: 5272

Try passing connection to sqlsrv_query

something like:

 $querychange = sqlsrv_query($conn, "UPDATE customers SET userPass='$newpassword' WHERE userName='$username'");

Upvotes: 2

Related Questions