I have two tables in one database.
id | title
--------- // table name is tableone
1 | a
2 | b
3 | c
4 | d
5 | a
6 | b
7 | c
8 | d
for the first table the primary key is the ID column. from this table I am using PHP to create a HTML table which works fine.
The second table
id | version
---------
a | 1
b | 3
c | 6
d | 7
in the while loop for the first table I have predefined the title value as
$title = $id['title'];
within the while loop i am using another while loop yet this time I am trying to use the predefined title to access the matching id’s corresponding version row value on the second table using :
mysql_query("SELECT version FROM tableone WHERE ID=".$title)
however i am hinted with the error
Unknown column ‘a’ in ‘where clause’
what is the problem and how can i fix it ?
You should must enclose the $title in quotes like this:
If you have user supplied input, you should make sure that your code is secure for all cases.
In this post are some good informations about that: https://stackoverflow.com/questions/3714107/php-mysql-security-checklist-the-definitive-practical-guide