脚本警报将PHP 5.3迁移到7.1

问题描述 投票:0回答:1

我有一组PHP文件从5迁移到7.1,每次尝试从注册帐户登录到登录页面时,我都会收到脚本错误,提示“未登录”。创建一个新用户并将其添加到数据库中可以正常工作,但是我对可能导致此错误的原因感到困惑。以前从未进行过迁移,因此我认为这是从MySQL到MySQLi的简单操作。

<?php

session_start();
include "configuration.php";
$user = $_REQUEST["user"];
$pass = $_REQUEST["pass"];
$sql = mysqli_query("select * from reg where user='$user' and pass='$pass'");
if ($qr1) {
    $row = $qr1->num_rows;
    if ($row == 1) {
        $fetch = $qr1->fetch_array();
        $_SESSION['id'] = $fetch['id'];
        echo "<script>alert('Successfully Logged In.')</script>";
        echo "<script>window.location.href='pro.php'</script>";
    } else {
        echo "<script>alert(' Please re-enter name and password correctly..')</script>";
        echo "<script>window.location.href='index.php'</script>";
    }
} else {
    echo "<script>alert('Not Logged In.')</script>";
    echo "<script>window.location.href='index.php'</script>";
}
php php-5.3 php-7.1 migrating
1个回答
-1
投票

[$qr1]变量未在任何地方定义,似乎是$sql

问题实际上与迁移无关。

请尝试以下代码:

  session_start();
  include "configuration.php";
  $user=$_REQUEST["user"];
  $pass=$_REQUEST["pass"];
  $sql = mysqli_query("select * from reg where user='$user' and pass='$pass'");
  $row=$sql->num_rows;
  if($row==1) {
    $fetch=$sql->fetch_array();
    $_SESSION['id']=$fetch['id'];
    echo "<script>alert('Successfully Logged In.')</script>";
    echo "<script>window.location.href='pro.php'</script>";

} else {
    echo "<script>alert('Not Logged In.')</script>";    
    echo "<script>window.location.href='index.php'</script>";
   }

您还想再次查看您的代码,但这只是节省时间。

© www.soinside.com 2019 - 2024. All rights reserved.