Jump to content

[SOLVED] Unknown column 'username' in 'where clause' please help


bogdaniel

Recommended Posts

hello can someone help me with this code please ? it gives this errors :-s

 

 

Notice: Undefined index: logged in C:\webserver\sandbox.dev\public_html\triburile\home.php on line 2

Notice: Undefined index: username in C:\webserver\sandbox.dev\public_html\triburile\home.php on line 19

Notice: Undefined index: password in C:\webserver\sandbox.dev\public_html\triburile\home.php on line 20
Unknown column 'username' in 'where clause'

 

 

<?php
if ($_SESSION['logged'] == 1) {
    echo '<div id="login">';
    echo '<div class="content">';
    echo '<form id="form1" method=\"POST\" action=\"login.php\">';
    echo '<fieldset>';
    echo '<legend>Sign-In</legend>';
    echo '<label for="inputtext1">Client ID:</label>';
    echo '<input id="inputtext1" type=\"text\" name=\"username\" value="username" />';
    echo '<label for="inputtext2">Password:</label>';
    echo '<input id="inputtext2" type=\"password\" name=\"password\" value="password" />';
    echo '<input id="inputsubmit1" type="submit" name=\"inputsubmit1\" value="Go Baby" /><br />';
    echo '<br /><br /><p>             <a href="#">Forgot your password?</a></p>';
    echo '</fieldset>';
    echo '</form>';
    echo '</div>';
    echo '</div>';
} else {
    $username = form($_POST['username']);
    $password = md5($_POST['password']); // Encrypts the password.

    $q = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or
        die(mysql_error()); // mySQL query
    $r = mysql_num_rows($q); // Checks to see if anything is in the db.

    if ($r == 1) { // There is something in the db. The username/password match up.
        $_SESSION['logged'] = 1; // Sets the session.
        header("Location: index.php"); // Goes to main page.
        exit(); // Stops the rest of the script.
    } else { // Invalid username/password.
        exit("Incorrect username/password!"); // Stops the script with an error message.
    }
}
?> 

 

 

 

This is the table:

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL auto_increment,
  `username` varchar(225) NOT NULL default '',
  `password` varchar(225) NOT NULL default '',
  `email` varchar(225) NOT NULL default '',
  PRIMARY KEY  (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.