Jump to content

Recommended Posts

[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 result

beginning to lose hair over this simple query, any help much appriciated
Link to comment
https://forums.phpfreaks.com/topic/27757-strange-phpmysql-error/
Share on other sites

[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 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 :(
[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?
[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 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,
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.