gpt4 book ai didi

php - 尽管数据库用户名和密码正确,但登录脚本无法正常工作

转载 作者:行者123 更新时间:2023-11-29 07:25:32 25 4
gpt4 key购买 nike

索引文件:

/*<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>

<title>SMB Login</title>


</head>

<body>
<form name="form1" method="post" action="checklogin.php">
-------begin -----
<div class="panel-body">
<form accept-charset="UTF-8" role="form">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="E-mail" name="email" type="text" id="username">
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" value="" id="password">
</div>
<div class="checkbox">
<label>
<input name="remember" type="checkbox" value="Remember Me"> Remember Me
</label>
</div>
<input class="btn btn-lg btn-success btn-block" type="submit" value="Login">
</fieldset>
</form>
----------etc

上面的脚本是我的登录页面的 HTML 代码,我添加了以下用于登录的 PHP 脚本。但是每次我输入正确的用户名密码时都会出现错误。

checklogin.php --> 源代码

<?php

ob_start();
$host="mysql"; // Host name
$username="admin"; // Mysql username
$password="XXX"; // Mysql password
$db_name="members_smb"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("username");
session_register("password");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
*/

请指出我哪里出错了???

最佳答案

在 SQL 字符串中,您插入 $username 和 $password,但这些变量不存在。您有 $myusername 和 $mypassword。

更改为:

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

您的代码还有很多错误,但这是问题的症结所在。

关于php - 尽管数据库用户名和密码正确,但登录脚本无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34714549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com