I'm trying to understand why a query on one column will work while a query on another column will not work. I use the following to create a table:
CREATE TABLE pages (
page_id TINYINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(200) NOT NULL,
PRIMARY KEY (page_id)
)
And this is the query I use on a template page:
$query = "SELECT * FROM pages WHERE page_id=".$_GET['page_id'];
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
I have some other code on the page to call various data from the row. When I go to sitename.com/template.php?page_id=1 it shows the data I want from the row where page_id=1, sitename.com/template.php?pade_id=2 shows the data I want from the row where page_id=2, etc.
Now, I change the query, replacing page_id with title:
$query = "SELECT * FROM pages WHERE title=".$_GET['title'];
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
When I go to sitename.com/template.php?title=title1 instead of showing the data from the row where I have a title = title1 I get an error that says Unknown column 'title1' in 'where clause'
Where am I going wrong? Why does it think title1 is the name of the column? I've tried using other columns instead of title and nothing works except page_id. Does it have something to do with how I setup my table? Thanks in advance for the help.