SQL编写的语句。PHP

SQL编写的语句。PHP,php,sql,Php,Sql,也许这个问题会有点“愚蠢的问题”,但仍然。。。 我不熟悉PHP和SQL,我不明白我在这里做错了什么: if(isset($_POST[$logButton])) //Checking for login button pressed { //Retrieving information from POST method $uid = $_POST['login']; $upwd = $_POST['password']; /

也许这个问题会有点“愚蠢的问题”,但仍然。。。 我不熟悉PHP和SQL,我不明白我在这里做错了什么:

if(isset($_POST[$logButton])) //Checking for login button pressed
    {
        //Retrieving information from POST method
        $uid = $_POST['login'];
        $upwd = $_POST['password'];
        //SQL Connection
        $mysqli = new mysqli('localhost', 'root', '', 'students');
        if(!$mysqli)
        {
            echo "<h1 class='h1A'>Problem accured while connecting to the DB. " . mysqli_error($mysqli) . "</h1>"; //!!!Delete displaying error msg after dev.
        }else
        {
            $sql = "SELECT * FROM login_data WHERE login = ? AND password = ?"; //SQL query
            $stmt = $mysqli->prepare($sql) or die("error1"); //No error
            $stmt->bind_param('ss', $uid, $upwd) or die("error2");//No error

            $stmt->execute() or die("error3");//Giving DB query. No error
            $result = $stmt->fetch() or die("error4".mysqli_error($mysqli)); //Putting query's result into assoc array. !!!Delete displaying error msg after dev. No error
            echo print_r($result); //It prints out "11" ? ? ?
            if(count($result['id']) < 1) //If no rows found.
            {
                echo "<h1 class='h1A'>Couldn't find account. Please, recheck login and password.</h1>";
                die();
            }elseif($result['id'] > 1)//If more then 1 row found.
            {
                echo "<h1 class='h1A'>Caught 9090 error. Contact the administrator, please.".mysqli_error($mysqli)."</h1>";
                die();
            }elseif($result['id'] == 1) //If only one row's been found.
            {
                $_SESSION['isLoggedIn'] = true;
                redirectTo('/index.php'); //Declared function.
                die();
            }
        }
    }
if(设置($\u POST[$logButton])//检查是否按下了登录按钮
{
//从POST方法检索信息
$uid=$\u POST['login'];
$upwd=$_POST['password'];
//SQL连接
$mysqli=newmysqli('localhost','root','students');
如果(!$mysqli)
{
echo“连接到数据库时出现问题”。.mysqli_错误($mysqli)。”;/!!!删除开发后显示的错误消息。
}否则
{
$sql=“从login_数据中选择*,其中login=?和password=?”;//sql查询
$stmt=$mysqli->prepare($sql)或die(“error1”);//无错误
$stmt->bind_参数('ss',$uid,$upwd)或die(“error2”);//无错误
$stmt->execute()或die(“error3”);//给出DB查询。无错误
$result=$stmt->fetch()或die(“error4”。mysqli_error($mysqli));//将查询结果放入关联数组。!!!删除开发后显示的错误消息。无错误
echo print_r($result);//它打印出“11”?
if(count($result['id'])<1)//如果找不到行。
{
echo“找不到帐户。请重新检查登录名和密码。”;
模具();
}elseif($result['id']>1)//如果找到超过1行。
{
echo“捕获9090错误。请与管理员联系。”.mysqli_错误($mysqli)。”;
模具();
}elseif($result['id']==1)//如果只找到一行。
{
$\u SESSION['isLoggedIn']=true;
重定向到('/index.php');//声明的函数。
模具();
}
}
}
下面是lib.php文件中处理函数的一部分。此文件包含在html页面中,并使用该函数。没有显示错误,当我打印\r$result时,它会打印出11。无法获取它。

好吧,使用无回声打印:

或者将第二个参数传递给print_r函数,以便它可以返回字符串:

echo print_r($result, true);

有关详细信息,请参阅。

切勿以明文形式存储密码!。只存储密码哈希!使用PHP的和。如果您运行的PHP版本低于5.5(我真的希望您不是),那么可以使用获得相同的功能。谢谢。我会用的。
echo print_r($result, true);