未定义的索引:从$ row = sqlsrv_fetch_array($ result)登录。为什么?

时间:2019-07-02 08:44:42

标签: php sql-server

我正在使用MSSQL服务器。我有来自不同数据库的2个杂文。在第一个表中,有用于所有个人的登录名和密码,在第二个表中有秘书ID。我想像一些秘书一样登录。但是数组行看不到“登录”字段。我的代码如下。

<?php
setcookie(sotrKod,"$sotrKod");
session_start();
ob_start(); 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);




$serverName = "MAIN";//
$connection = array("Database" => "usersINEU","UID" => "user_007", "PWD" => "updpswpspu007");
$conn = sqlsrv_connect($serverName, $connection);


//Проверка логина и пароля
//Если логин и пароль из формы переменые не пусты т.е. true
if(isset($_POST['username']) and isset($_POST['password'])) {
     //то присваеваем их переменым для php
     $username =  $_POST['username'];
     $password = $_POST['password'];

     //Выполяем запрос поиска и сравнивание
 $sql = ("SELECT * FROM [College].[dbo].[tb_Secret] WHERE [Kod] IN ( 
SELECT [KodSotr] FROM [usersINEU].[dbo].[tbUsersPGPI]  WHERE (Login = '" .$username. "') AND (Passw = '" .$password. "'))");  
 /*("SELECT KodSotr, Login, Passw FROM [usersINEU].[dbo].[tbUsersPGPI]
 WHERE (Login = '".$username."') AND (Passw =  '".$password."') ");*/
 echo $sql;
 /*
 $sql = "SELECT Login, Passw, Disable FROM dbo.MAIN_usersINEU_dbo_tbUsersPGPI WHERE (Login = '" & txtNameUsers.Value & "') AND (Passw = '" & txtKodPodraz.Value & "' ) ";
$query = mssql_query("SELECT id FROM users WHERE username = '{$username}' and password = '{$password}'");*/
    /* $result = sql_query($conn, $query) or die ("Ошибка");
     $count = mysqli_num_rows($result); */

       $result = sqlsrv_query($conn, $sql);

echo $result;
 while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
    echo $row['Login'];
    //$row = sqlsrv_fetch_array($result)
     if ($row['Login'] == $username ) {
         echo "rabotaet";
        /*$row = sqlsrv_fetch_array($result);*/
        $_SESSION['KodSecr'] = $row['KodSecr'];
        $_SESSION['KodSotr'] = $row['KodSotr'];

     } 
 } 
}
  if (isset($_SESSION['KodSotr'])){


    $KodSotr = $_SESSION['KodSotr'];
    setcookie("sotrKodVhod", $KodSotr);
    header("Location: /testum/sample.php");
    }/*else {

        header("Location: /testum/index.php?nologin=1");

     }*/

?>

它向我显示此错误注意:未定义的索引:在第40行的/var/www/html/testum/proverka.php中登录。为什么?为什么row ['Login']不存在?我不理解

0 个答案:

没有答案