Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable to MySQL query

Status
Not open for further replies.

bill1one

Programmer
Sep 29, 2004
93
0
0
US
In my form, I'm trying to pass the following values to a MySQL query.
Code:
Sort by:
 <select name="sort" type="text">
  <option value="Title, Author">Title</option>
  <option value="Lexile, Title">Lexile</option>
 </select>
For some reason the MySQL totally ignores the values posted and does not order the data. Here's what I have in the php page that the values are posted to.
Code:
$sort = $_POST['sort'];

$query = "SELECT Title, Author, Lexile, School FROM booklist ORDER BY ('$sort')";
I believe it has to do with the commas in the value string, but I'm not sure. I'm using MySQL 5.0 and PHP 5.1.4.

Any suggestions would be appreciated. Thanks.
 
try:

Code:
$query = "SELECT Title, Author, Lexile, School FROM booklist ORDER BY [red]" . $sort[/red];

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
try this
Code:
$query = "SELECT Title, Author, Lexile, School FROM booklist ORDER BY $sort";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top