Re: Run a SQL query based on HTML drop down selection?



Joe wrote:
This is my HTML form:

<form method=get action="home.php">
<INPUT TYPE = "Text" VALUE = "" NAME = "title"><br>
<select name="searchby">
<option value="Title">Title</option>
<option value="Year">Year</option>
<option value="Genre">Genre</option>
<option value="Director">Director</option>
</select>

And here is the relevant PHP query:

$query = "SELECT Title, ReleaseYear, Rating, Director, RunningTime,
Genre
FROM movie
WHERE $searchby LIKE '%$title%'
GROUP BY $searchby";

Assume that "$title" is a string of text (not necessarily a movie
title). My problem seems to be that I cant use the variable $searchby
within a SQL query. Is there a workaround for this?


There should be no problem - as long as your columns are named Title, Year, Genre and Director.

What do you get when you echo $query, and what is your error message?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • One To Many To One Common Problem
    ... This seems to be a perrenial problem with many database designs. ... Using a simple example of a movie database (but I have other ... foreign key for GENRE. ... The query that this is based on contains all the MOVIEGENRE records, ...
    (microsoft.public.access.forms)
  • Re: One To Many To One Common Problem
    ... A query on table MOVIE ... MOVIEGENRE forms the recordsource for the subform. ... all the rows in table GENRE. ...
    (microsoft.public.access.forms)
  • Re: Run a SQL query based on HTML drop down selection?
    ... And here is the relevant PHP query: ... FROM movie ... My problem seems to be that I cant use the variable $searchby ... within a SQL query. ...
    (comp.lang.php)
  • Re: Run a SQL query based on HTML drop down selection?
    ... And here is the relevant PHP query: ... Assume that "$title" is a string of text (not necessarily a movie ... My problem seems to be that I cant use the variable $searchby ... Year, Genre and Director. ...
    (comp.lang.php)
  • Re: Run a SQL query based on HTML drop down selection?
    ... And here is the relevant PHP query: ... Genre ... Assume that "$title" is a string of text (not necessarily a movie ... My problem seems to be that I cant use the variable $searchby ...
    (comp.lang.php)