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

时间:2015-08-06 10:12:53

标签: php mysql web easyphp

第一次在这里发帖,因为我对如何解决我的问题毫无头绪,我一直在寻找过去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();
}

?>

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

感谢您花时间阅读本文,并在您决定的时候提供帮助。

-Ryan

1 个答案:

答案 0 :(得分:1)

$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是您正在进行查询的表的名称