SetToLoki Posted November 19, 2006 Share Posted November 19, 2006 [code=php:0]$username = trim($_POST['username']);$password = md5($_POST['password']);$query = "select username, userlevel from users where users.username= '$username' and password='$password'";echo $query."<br />";[/code]This is the query I am sending to the database all looks good as it is, but when I fill my login form in on my site I am left with this error[code]select username, userlevel from users where users.username= 'tom' and password='xxxxxx'Unknown column 'tom' in 'where clause'[/code]My first thoughts was maybe I forgot the ' around my $username but they are there. re wrote the query a few times added things like trim() to the username just incease it was grabbing random white space from somewhere, but having no luck also changed my call from username to users.username and swapped the order it searches for the username and password, but always finds the problem with the username field.if I am to use my echoed query into mysql through say zend, it returns the expected resultbeginning to lose hair over this simple query, any help much appriciated Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/ Share on other sites More sharing options...
Orio Posted November 19, 2006 Share Posted November 19, 2006 Try:select username, userlevel from users where username= 'tom' and password='xxxxxx'The only thing I dont get is- why do you pull the username from the database if you have "where username=..." ?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127047 Share on other sites More sharing options...
AV1611 Posted November 19, 2006 Share Posted November 19, 2006 $query = "select username, userlevel from users where `username` = '$username' and `password`='$password'"; Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127078 Share on other sites More sharing options...
SetToLoki Posted November 19, 2006 Author Share Posted November 19, 2006 [quote author=Orio link=topic=115529.msg470499#msg470499 date=1163947065]Try:select username, userlevel from users where username= 'tom' and password='xxxxxx'The only thing I dont get is- why do you pull the username from the database if you have "where username=..." ?Orio.[/quote]more trial and error stuff to see if it helped :D it didn't :( Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127168 Share on other sites More sharing options...
SetToLoki Posted November 19, 2006 Author Share Posted November 19, 2006 [quote author=AV1611 link=topic=115529.msg470531#msg470531 date=1163953271]$query = "select username, userlevel from users where `username` = '$username' and `password`='$password'";[/quote]select username, userlevel from users where `username` = 'tom' and `password`='xiexiex'Unknown column 'tom' in 'where clause'still being buggy :( Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127169 Share on other sites More sharing options...
SetToLoki Posted November 19, 2006 Author Share Posted November 19, 2006 [code=php:0]function Login(){ $form = '<div id="login" class="right_cont"> <form action="%s" method="post" name="login"> <h2>Login </h2> %s username<br /> <input class="input" name="username" type="text" id="username" /><br /> password<br /> <input class="input" name="password" type="password" id="password" /><br /> <input class="submit" name="submit" value="submit" type="submit" /> <div id="reg"><a href="%s">Register</a> || <a href="">Lost Password</a></div> </div>'; if (!isset($_SESSION['user'])) { if (!isset($_POST['username'])) { printf ($form, "","",$_SERVER['PHP_SELF'].'?p=register',"",""); } if (isset($_POST['username'])) { //First Time login details have been added $username = trim($_POST['username']); $password = md5($_POST['password']); $query = "select username, userlevel from users where `username` = '$username' and `password`='$password'"; echo $query."<br />"; $res = mysql_query($query); echo $res."<br />"; $count = mysql_num_rows($res); if ($count == 1) { //succsesful match found log in $res = mysql_fetch_array($res); $_SESSION['user'] = $res['username']; $_SESSION['userlevel'] = $res['userlevel']; $query = sprintf("UPDATE users SET users.LastLogin = %s WHERE users.username = %s",date(Ymd),$_SESSION['user']); mysql_query($query) or die(mysql_error()); } else { //Login Failure printf($form, "", "<p>Login Failed: please check your username and password are correct.</p>","",""); } } } else {echo '<div id="login">You are logged in as <b>'.$_SESSION['user'].'</b></ br> <a href="'.$_SERVER['PHP_SELF'].'?p=profile">Edit Profile</a> || <a href="'.$_SERVER['PHP_SELF'].'?p=pref">My Personal Options</a> || <a href="'.$_SERVER['PHP_SELF'].'?p=logout">Logout</ a></div>'; } }[/code]maybe the full function will spread mroe light? Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127172 Share on other sites More sharing options...
SetToLoki Posted November 21, 2006 Author Share Posted November 21, 2006 desperate bump Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127844 Share on other sites More sharing options...
taith Posted November 21, 2006 Share Posted November 21, 2006 [code]select username, userlevel from users where users.username= 'tom' and password='xxxxxx'Unknown column 'tom' in 'where clause'[/code]that is simply telling you that your mysql doesnt have a collumn named 'tom', get rid of the space seperating username= 'tom', that should fix it... Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127885 Share on other sites More sharing options...
SetToLoki Posted November 21, 2006 Author Share Posted November 21, 2006 [quote author=taith link=topic=115529.msg471347#msg471347 date=1164113043][code]select username, userlevel from users where users.username= 'tom' and password='xxxxxx'Unknown column 'tom' in 'where clause'[/code]that is simply telling you that your mysql doesnt have a collumn named 'tom', get rid of the space seperating username= 'tom', that should fix it...[/quote]one of my first thoughts, but doesn't seem to make a diffrence, I have even opened tutorials that do the same sort of thing and copied and pasted their code into my scrtiop, no matter what I do it always belives there should be a coloum with same name as $username, if after running the script and getting the error I refrewsh or change page, I am logged in as I should be, so the script functions as it should, only it gives me an error, Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127891 Share on other sites More sharing options...
HuggieBear Posted November 21, 2006 Share Posted November 21, 2006 What happens if you use:[code]SELECT username, userlevel FROM users WHERE username = 'tom' AND password = 'xxxxxx'[/code]I just wondered why you're specifying the table in the WHERE clause?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-127892 Share on other sites More sharing options...
AV1611 Posted November 22, 2006 Share Posted November 22, 2006 Just for fun, do "select * from..." then printf the resultsCurious... Quote Link to comment https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/#findComment-128353 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.