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 ;

line2:

if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) {

 

line19: Apparently no username has been posted from form

line20: and no password

 

 

There's no column called 'username' in 'users' table.

Change VARCHAR(255) for password to CHAR(32)

It'll always have this length, and some say that CHAR is a bit faster than VARCHAR. I' ve never seen any benchmarks, but well... nothing to loose ;)

 

thanks for advice i made the changes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.