Reputation: 145
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.
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.
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. 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
Upvotes: 1
Views: 706
Reputation: 5665
$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
Upvotes: 1