gpt4 book ai didi

php - 通知: Undefined variable: dbname

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

注意: undefined variable :dbname

找不到用户名

我无法从 mysql 数据库获取用户名和密码,也许你知道问题出在哪?

...................................................... ................................................

page2.php

<?php
session_start();
?>
<html>
<head>
</head>
<body>
<?php
require ('sql_connect.php');
if(isset($_POST['submitlogin'])){
$username = mysql_escape_string($_POST['usernameinput']);
$password = mysql_escape_string($_POST['passwordinput']);
if($username == $dbname){
if($password == $dbpass){
$_SESSION['currentuser'] = $username;
$_SESSION['currentaccesslevel'] = 5;
echo "welcome back, " . $username;
}
else {
showform('wrong password');
}
}
else {
showform("username not found");
}
}
else {
showform("please enter your username and password");
}
function showform($message){
include ('form.php');
echo $message;
}
exit();
mysql_query("SELECT * FROM `user_data` WHERE `username`='$dbname' `password`='$dbpass'");
?>

...................................................... ................................................

sql_connect.php

<?php
mysql_connect("localhost", "root", "") or die("mysql connection is failure.");
mysql_select_db("users") or die("Database does not exists.");
?>

...................................................... ................................................form.php

<html>
<head>
</head>
<body>

<form method="post" action="page2.php" />
<input type="text" name="usernameinput" />
<input type="text" name="passwordinput" />
<input type='submit' value='submit' name='submitlogin' />
</form>

</body>
</html>

...................................................... ................................................

最佳答案

在使用它们之前,您必须定义$dbname。在上面的代码中,$dbname 未定义,您正在比较它。这就是错误出现的原因。

if($username == $dbname){
if($password == $dbpass){

首先定义它们

$dbname = //some value;
$dbpass = //some value;

if($username == $dbname){
if($password == $dbpass){

关于php - 通知: Undefined variable: dbname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26800910/

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