Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 393
zoro724 Avatar asked Mar 20 '26 11:03

zoro724


1 Answers

Try passing connection to sqlsrv_query

something like:

 $querychange = sqlsrv_query($conn, "UPDATE customers SET userPass='$newpassword' WHERE userName='$username'");
like image 111
elrado Avatar answered Mar 21 '26 23:03

elrado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!