wherer clause error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

wherer clause error

Post 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
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Quotes

Post 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'";
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

thanks very much.
Post Reply