I am trying to create a login system for my server. I have used similar code for my local website using xampp but now I am trying for an external server. The error i am getting is this.
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '
'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '
'. ) )
and my code is below:
<?php
session_start();
$inputuser = $_REQUEST['Username'];
$inputpass = $_REQUEST['Password'];
$Server = "MyServer";
$user = "user";
$password = "pass";
$database = "mydb";
$table = "users";
$connectionInfo = array( "Database"=>$database,"UID"=>$user, "PWD"=>$password);
$link = sqlsrv_connect($Server, $connectionInfo);
if ($link === false) {
echo "Connection failed. n";
die(print_r(sqlsrv_errors(), true));
}
$query = "SELECT `Username` FROM `onlinereporting` . `users` WHERE `Username` = '$inputuser'";
$querypass = "SELECT `Password` FROM `onlinereporting` . `users` WHERE `Password` ='$inputpass'";
$result = sqlsrv_query($link,$query);
$resultpass = sqlsrv_query($link,$querypass);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($result);
$rowpass = sqlsrv_fetch_array($resultpass);
$serveruser = $row["Username"];
$serverpass = $rowpass["Password"];
if ($serveruser And $serverpass) {
header('Location: index.html');
}
else {
header('Location: FailedPage.html');
}
?>
The connection is working fine, the only problem occurs when I try to check if the result is false.
When i am not trying to check the $result, everything I insert is considered as a wrong username and password.
Any help or advice is welcome.
Aucun commentaire:
Enregistrer un commentaire