Page 1 of 1

wherer clause error

Posted: Sun Feb 25, 2007 3:24 pm
by sarris
Hi there.
I am having a very weird problem on the easiest clause ever.
i have this table created

Code: Select all

CREATE TABLE `user_home` (
  `user` varchar(20) NOT NULL default '',
  `homeid` int(11) NOT NULL default '0',
  PRIMARY KEY  (`user`,`homeid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
i have this variable in php

Code: Select all

$username =  $_GET['username'];
and this sql querry

Code: Select all

$sql = "SELECT
		homeid
	FROM
		user_home
where user_home.user = $username";
Seems as the simplest of querries

When the querry is executed i get this error
Could not query:Unknown column 'smith' in 'where clause'
where smith is one of the username and the user that called this script.
any help would be really appreciated.
thanks

Quotes

Posted: Sun Feb 25, 2007 4:44 pm
by veridicus
You need to wrap the name in quotes so the query is syntactically correct.

Code: Select all

$sql = "SELECT 
                homeid 
        FROM 
                user_home 
where user_home.user = '$username'";

Posted: Sun Feb 25, 2007 5:04 pm
by sarris
thanks very much.