<?php
ob_start();
session_start();
$host="localhost";
$user="x";
$pass="x";
$db="x";
$tbl_name="users";
$mysqli = mysqli_connect($host, $user, $pass, $db);
$mypassword=$_POST['code'];
$mypassword = stripslashes($mypassword);
$mypassword = $mysqli->real_escape_string($mypassword);
$encrypt_password=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE password='$encrypt_password'";
$result=$mysqli->query($sql);
$count=mysqli_num_rows($result);
if($count==1) {
$_SESSION['mypassword']="$mypassword";
header("index/index.php");
}
}
?>
答案 0 :(得分:1)
您好需要将查询编辑为以下内容:
$sql="SELECT * FROM $tbl_name WHERE password='$encrypt_password' AND `username`='$myusername'";
As if you have
$count=mysqli_num_rows($result);
if($count==1) {
// it means your user is in a db and it could be marked as logged in
header("Location: index/index.php");
}
答案 1 :(得分:1)
获取查询返回的行并从中获取用户名。
if ($count == 1) {
$row = $result->fetch_assoc();
$_SESSION['username'] = $row['username'];
header("Location: index/index.php");
}