Hello, i have a login page for home i have created a database and connected my database to it. My code is:


<!DOCTYPE html>

<html lang='en'>
    <meta charset="UTF-8" /> 
        HTML Document Structure
    <link rel="stylesheet" type="text/css" href="style.css" />

<div id="wrapper">

    <form name="login-form" class="login-form" action="check_user.php" method="post">

        <div class="header">
        <h1>Login Form</h1>
        <span>Fill out the form below to login to my super awesome imaginary control panel.</span>

        <div class="content">
        <input name="username" type="text" class="input username" placeholder="Username" />
        <div class="user-icon"></div>
        <input name="password" type="password" class="input password" placeholder="Password" />
        <div class="pass-icon"></div>     

        <div class="footer">
        <input type="submit" name="submit" value="Login" class="button" />
        <input type="submit" name="submit" value="Register" class="register" />


<div class="gradient"></div>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Credentials</title>

$connection = mysql_connect('localhost','root','');
    die("Database Connection Failed". mysql_error());
$select_db = mysql_select_db('hamdard_attendance');
    die("Database Connection Failed" . mysql_error());

if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];

$query_one = "SELECT * FROM 'users' WHERE 'username' = $username AND 'password' = $password";
$result = mysql_query($query_one) or die(mysql_error());
$count = mysql_num_rows($result);

if ($count == 1){
$_SESSION['username'] = $username;
echo "Invalid Login Credentials.";
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
echo "Hai " . $username . "
echo "This is the Members Area";


I am having the following error.

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 ''users' WHERE 'username' = jerry AND 'password' = 12345' at line 1

Can someone please help me out regarding this?

Try this:

$query_one = "SELECT * FROM 'users' WHERE 'username' = '".$username."' AND 'password' = '".$password."'";

@lps: The single quotes around the table and column names are wrong. Either remove them or use backticks.

thank you buddy! its being solved! .. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.