gpt4 book ai didi

php - EasyPHP 无法将数据库链接到 PHP 文件

转载 作者:行者123 更新时间:2023-11-28 23:55:17 25 4
gpt4 key购买 nike

第一次在这里发帖,因为我对如何解决我的问题一无所知,过去 2 小时我一直在寻找修复程序,但一直没能找到。

我已经启动并运行了我的网站,主要是 html,然后我有一个应该连接到 EasyPHP 数据库的登录页面,但我无法将登录页面链接到数据库,我有一个 connectivity.php 文件启动连接并检查用户名和密码,但我一直收到错误消息。

登录页面代码:

<html>
<head>
<title>Sign In</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>

</head>
<body>
<div id="container">

<header>

<a href="index.html"><img src="images/Header.jpg" alt="logo" /></a>

</header>


<header>
<a href="login.html"><img src="images/login.jpg" alt="login" /></a>
<a href="https://www.facebook.com/ArcticMonkeys"><img src="images/Facebook.jpg" alt="FB" /></a>
<a href="https://twitter.com/arcticmonkeys"><img src="images/Twitter.jpg" alt="Twitter" /></a>

</header>

<div class="menu">
<div align="center">
<ul class="list">
<li class="item"><a href="index.html"#">Home</a>
<li class="item"><a href="gallery.html"#">Gallery</a>
<li class="item"><a href="videos.html"#">Videos</a>
<li class="item"><a href="discography.html"#">Discography</a>
<li class="item"><a href="register.html"#">Register</a>

<li class="item"><a href="#">About</a>
<ul class="list">
<li><a href="alex.html">Alex Turner</a></li>
<li class="list">
<a href="matt.html">Matt Helders</a>
<ul class="list">
<a href="jamie.html">Jamie Cook</a>
<ul class="list">
<a href="nick.html">Nick O'Malley</a>
<ul class="list">
<a href="andy.html">Andy Nicholson</a>
<ul class="list">
</ul>
</li>


</div>
</div>

</head>
<div align="center"><BR><BR><BR><BR>
<body id="body-color">

<div id="Sign-In">

<fieldset style="width:30%"><legend>LOG-IN HERE</legend>

<form method="POST" action="connectivity.php">

User <br><input type="text" name="user" size="40"><br>
Password <br><input type="password" name="pass" size="40"><br>
<input id="button" type="submit" name="submit" value="Log-In">
</form>

</fieldset>

<br><br>
<br><br>

<H3>If you do not have an account please register <a href="register.html">
HERE</a><br>otherwise access is restricted to member pages<h3>

</div>

</body>

</html>

Connectivity.php 页面我已经为此更改了很多代码以寻找解决方案,任何明显的错误都非常有帮助,因为此刻我的大脑被炸了。如果这些错误有帮助,我也会收到这些错误

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in G:\EasyPHP-DevServer-14.1VC11\data\localweb\my portable files\Website\connectivity.php on line 9
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Ryan' AND pass = '1234'' at line 1

这是页面代码

<?php
define('DB_HOST', 'localhost'); /*Database host 127.0.0.1 which is local host*/
define('DB_NAME', 'Users'); /*Database Name*/
define('DB_USER','usename');
define('DB_PASSWORD','');

/*Establishing a connection to the database
*/
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
/*
$ID = $_POST['user'];
$Password = $_POST['pass'];
*/
function SignIn()
{
session_start(); //starting the session for user profile page
if(!empty($_POST['user'])) //checking the 'user' name which is from Register.html, is it empty or have some text

/*SQL Query to validate the Username and and password combination */
{
$query = mysql_query("SELECT `ID`, `Pass` FROM `username` = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());
$row = mysql_fetch_array($query) or die(mysql_error());
if(!empty($row['userName']) AND !empty($row['pass']))
{
$_SESSION['userName'] = $row['pass'];
echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";

}
else
{
echo "SORRY... YOU ENTERD WRONG ID AND PASSWORD... PLEASE RETRY...";
}
}
}
if(isset($_POST['submit']))
{
SignIn();
}

?>

非常感谢任何对此的帮助!

感谢您抽出宝贵时间阅读本文,如果您决定提供帮助,我们将不胜感激。

-瑞安

最佳答案

$query = mysql_query("SELECT `ID`, `Pass` FROM `username` = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());

应该是

$query = mysql_query("SELECT `ID`, `Pass` FROM TABLE_NAME WHERE `username` = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());

TABLE_NAME 是你查询的表名

关于php - EasyPHP 无法将数据库链接到 PHP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31853005/

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