1

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

7
  • SELECT ID, Pass FROM username = '$_POST[user]' AND pass = '$_POST[pass]' should be SELECT ID, Pass FROM tablename WHERE username = '$_POST[user]' AND pass = '$_POST[pass]' Commented Aug 6, 2015 at 10:15
  • 1
    Plus, as the Deprecated message tells you, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. Commented Aug 6, 2015 at 10:17
  • That worked but still receiving an error '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' 'code' Failed to connect to MySQL: Access denied for user ''@'localhost' to database 'users' Commented Aug 6, 2015 at 10:18
  • 1
    I know your problem is with SQL but you may additionaly want to check your html - you have several problems with it. <a href="index.html"#"> - this contains extra double quote you may want to escape it. There is an extra </head> inside body somewhere. And above all you may want to add a doctype. All these thing may not cause problems at first but may fire later when you are least expecting it. Commented Aug 6, 2015 at 10:23
  • Have changed the code to fix the errors @Olga Didn't even notice those, thank you for pointing them out. Commented Aug 6, 2015 at 10:44

1 Answer 1

1
$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

Sign up to request clarification or add additional context in comments.

2 Comments

After changing that i am now receiving this error Unknown column 'ID' in 'field list' That is when i try login.
paste your table schema here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.