Code:
<?php
if (isset($_REQUEST['g'])) {
if ($_REQUEST['g'] == "Set") {
$g = strtolower($_REQUEST['g'])."_title";
}else{
$g = strtolower($_REQUEST['g']);
}
$result1 = mysql_query("SELECT LEFT($g, 1) FROM cards GROUP BY $g ORDER BY $g ASC");
while ($row = mysql_fetch_array($result1)) {
?>
<a href="./index.php?route=<?php echo $var[0]."/".$var[1]."&g=".$_REQUEST['g']; ?>&sort=<?php echo substr($row[$g], 0, 1); ?>"><?php echo substr($row[$g], 0, 1); ?></a>
<?php
}
}
?>
Error Message:
Notice: Undefined index: set_title in E:\xampp\htdocs\zipdown\include\sort.php on line 11
What am i missing?
Don’t forget to escape the value of
$gif it isn’t known to beSet.Alias the column created by
LEFT()as$g, enclosed in backticks:Otherwise, the column name returned by your
mysql_fetch_array()call is something like:Note on security:
Given that your database must have a finite set of column names, it is advisable to use a whitelist against which you check the value of
$g: