I have created a dropdown menu and wish to use the variable so acquired to select a column in MySQL query. I have used the following code:
<select name="selectedvalue">
<option value="n1">Birthweight</option>
<option value="n2">3-month weight</option>
<option value="n3">6-month weight</option>
</select>
Later I am retrieving the variable using
$selval = ($_POST['selectedvalue']);
MySQL query:
$lambings = "Select year, `".($_POST['selectedvalue'])."` as weight from mytable
GROUP by year(dob)";
but the sql query fails every time.
$selvalor$_POST['selectedvalue']?print($lambings);exit;and copy/paste the query does it run via phpMyAdmin or mysql-workbench, etc. ?$lambings? What driver are you using? This is open to SQL injections.