简体   繁体   English

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

[英]EasyPHP Can't link database to PHP file

First time posting here as i am clueless on how to fix my problem, I've been searching for the past 2 hours on a fix but haven't been able to find one. 第一次发布此消息是因为我对如何解决问题一无所知,在过去的2个小时中,我一直在寻找解决方法,但一直找不到。

I have my website up and running, mostly html, then I have a login page which is supposed to be connected to a EasyPHP database, but I cannot link the login page to the database, I have a connectivity.php file to initiate the connection and check the username and password but I keep receiving errors. 我的网站已启动并正在运行,主要是html,然后我有一个登录页面,该页面应该连接到EasyPHP数据库,但是我无法将登录页面链接到数据库,我有一个Connectivity.php文件来启动连接并检查用户名和密码,但我仍然收到错误消息。

Login Page Code: 登录页面代码:

<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 Page I have Changed the code around on this a lot looking for a solution, any ovbious mistake is more than helpful as my brain is fried at the moment. Connectivity.php页面我已经在此上更改了很多代码以寻找解决方案,任何可疑的错误都无济于事,因为我的大脑此刻被炸了。 I also recieved these errors if they're helpful 如果它们有帮助,我也会收到这些错误

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

Here is the page code 这是页面代码

<?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();
}

?>

ANY help with this at all is greatly appreciated! 非常感谢您提供任何帮助!

Thank's for taking the time to read this and help out if you decide to. 感谢您抽出宝贵的时间阅读本文档,如果您愿意的话可以提供帮助。

-Ryan -Ryan

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

should be 应该

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

TABLE_NAME is the name of table for which you are doing query TABLE_NAME是您要查询的表的名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM