I am using a PHP variable inside a MySQL query but only to ORDER BY. I usually just enclose the variable in single quotes and it works.
Like this:
$sorter = $_GET[‘sorter’];
mysql_select_db($database_mtt, $mtt);
$query_rs_leaders = "SELECT * FROM hfleaders ORDER BY ‘$sorter’ ";
$rs_leaders = mysql_query($query_rs_leaders, $mtt) or die(mysql_error());
$row_rs_leaders = mysql_fetch_assoc($rs_leaders);
$totalRows_rs_leaders = mysql_num_rows($rs_leaders);
But in this case it only works first time round - when the page reloads I get the error
*** 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 ‘’ at line 1 ***
I have tried using {$sorter} instead but the same thing happens - it works once then not al all.
Can anyone explain why because I just can’t figure it out.
underneath the variable above to “see” what the query is returning.
Since it works on the first page load it should work on the refresh --depending on how the data is passed back to it. Maybe you are clicking on a link or button for form…I don’t know.