Jump to content

Recommended Posts

Hello,

can anybody tell me whats wrong with my code:

 

function check_login($uname, $pwd){
            $sql = "SELECT * FROM users WHERE uname=$uname";
            $result = mysql_query($sql) or die('Error, Load query failed: ' . mysql_error());
            $data = array();
            while($row=mysql_fetch_assoc($result)){
                $data[] = $row;
            }
        return $data;
}

$chk = check_login("test", "test1");
foreach($chk as $row){
        echo $row['uname'];
        echo " = ";
        echo $row['pass'];
        echo "<BR>";
    }

 

when i run this i get: 

Error, Load query failed: Unknown column 'test' in 'where clause'

Link to comment
https://forums.phpfreaks.com/topic/217660-mysql-error/
Share on other sites

Not really.  as i see on W3school:

SELECT column_name(s)
FROM table_name
WHERE column_name operator value 

example:
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");

 

and this is exactly what i did.

the "uname" is the column and the $uname is the value.

 

Link to comment
https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129916
Share on other sites

is $uname containing string value? if yes, try '$uname'... and also try putting backslashes to your column name `uname`....

i faced this error before and this fixed it....

 

You mean backticks, not backslashes . . .

Link to comment
https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129930
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.