Jump to content

mysql error


roeyhaim

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

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.