gpt4 book ai didi

php - undefined variable : Name in mysql PHP

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

enter image description here如果登录信息错误,系统将正确显示“登录失败”。

但如果详细信息正确,系统将在第25行显示“C:\Users\Alex\Desktop\OSMAD\8.5\root\Project\test3.php”< br/>登录失败”

这里是 PHP 文本

<?php

$host = "127.0.0.1";

$username = "root";

$password = "usbw";

$dbname = "forum_system";

// Connect to server
$connect = mysql_connect($host, $username, $password)
or die ("Sorry, unable to connect database server");

$dbselect = mysql_select_db($dbname,$connect)
or die ("Sorry, unable to connect database");

$Name = $_POST['Name'];
$Password = $_POST['Password'];

$result = mysql_query("select * from users where name = '$Name' and
password = '$Password'")
or die("Sorry, query failed".mysql_error());

$row = mysql_fetch_array($result);

if ( $row['Name'] == $Name && $row['Password'] == $Password ) {
echo "welcome";
} else {
echo "Fail login";
}
?>

最佳答案

MySQL 表列名称区分大小写。因此,您应该使用 $row['name']$row['Name']$row['Password'] 来代替$row['密码']。所以这行:

if ( $row['Name'] == $Name && $row['Password'] == $Password ) 

应替换为:

if ( $row['name'] == $Name && $row['password'] == $Password )

也可以使用mysqliMySQL_PDO而不是 mysql 函数。 Php 7.0.0 中删除了 mysql 扩展。

关于php - undefined variable : Name in mysql PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56734528/

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