bogdaniel Posted September 18, 2008 Share Posted September 18, 2008 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 ; Quote Link to comment https://forums.phpfreaks.com/topic/124838-solved-unknown-column-username-in-where-clause-please-help/ Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124838-solved-unknown-column-username-in-where-clause-please-help/#findComment-644909 Share on other sites More sharing options...
bogdaniel Posted September 18, 2008 Author Share Posted September 18, 2008 thanks for you help. problems solved Quote Link to comment https://forums.phpfreaks.com/topic/124838-solved-unknown-column-username-in-where-clause-please-help/#findComment-644914 Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124838-solved-unknown-column-username-in-where-clause-please-help/#findComment-644915 Share on other sites More sharing options...
bogdaniel Posted September 18, 2008 Author Share Posted September 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124838-solved-unknown-column-username-in-where-clause-please-help/#findComment-644934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.