dmilani
01-03-2007, 03:51 AM
Hi Folks,
I am trying to pass a MySQL query variable from a URL. It is only working sometimes and I can't figure out why. Here is the pertinent PHP:
$sortvar = $_GET['sortvar'];
if (empty($sortvar)) {
$sortvar= 'tname' ;
}
$query = "SELECT tname, contact, email, reqdiv, day, eve, cell, misc FROM $tabsel WHERE sess_two= 'yes' ORDER BY '$sortvar' ASC";
I displaying the data in a table and what to sort by clicking on the headers of the table. The relevant HTML here is:
echo "<tr>" .
"<th><a href=\"RegDisplay1.php?sortvar=tname\">Team Name</a></th>" .
"<th><a href=\"RegDisplay1.php?sortvar=reqdiv\">Req Division</a></th>" .
"<th><a href=\"RegDisplay1.php?sortvar=contact\">Contact</a></th>" .
"<th><a href=\"RegDisplay1.php?sortvar=email\">Email</a> " ;
The table displays fine when viewed directly but when clicking the link to sort I get this error:
Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE sess_two= 'yes' ORDER BY 'email' ASC' at line 1
Any insight would be greatly appreciated.
Dan
P.S. Is there an official term to describe the passing of variables from a URL to PHP? I have tried to search for this and don't think I have been using the proper terms.
I am trying to pass a MySQL query variable from a URL. It is only working sometimes and I can't figure out why. Here is the pertinent PHP:
$sortvar = $_GET['sortvar'];
if (empty($sortvar)) {
$sortvar= 'tname' ;
}
$query = "SELECT tname, contact, email, reqdiv, day, eve, cell, misc FROM $tabsel WHERE sess_two= 'yes' ORDER BY '$sortvar' ASC";
I displaying the data in a table and what to sort by clicking on the headers of the table. The relevant HTML here is:
echo "<tr>" .
"<th><a href=\"RegDisplay1.php?sortvar=tname\">Team Name</a></th>" .
"<th><a href=\"RegDisplay1.php?sortvar=reqdiv\">Req Division</a></th>" .
"<th><a href=\"RegDisplay1.php?sortvar=contact\">Contact</a></th>" .
"<th><a href=\"RegDisplay1.php?sortvar=email\">Email</a> " ;
The table displays fine when viewed directly but when clicking the link to sort I get this error:
Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE sess_two= 'yes' ORDER BY 'email' ASC' at line 1
Any insight would be greatly appreciated.
Dan
P.S. Is there an official term to describe the passing of variables from a URL to PHP? I have tried to search for this and don't think I have been using the proper terms.