I am trying to echo out or print out the query results from this radio button:
<input type="radio" name="Query" value="SELECT employees.name FROM employees, department WHERE employees.department_deptID=department.deptID AND department.departName="Information Technology""> List all employees in a particular department (Information Technology).<br />
The code I currently am using is this:
if ($_POST['submit'] == "submit" && isset($_POST['Query'])){
$query = $_POST['Query'];
$result = mysql_query($query);
print $query;
while($row = mysql_fetch_assoc($result)){
foreach($row as $cname => $cvalue){
print "$cname: $cvalue\t";
}
print "
";
}
}
Along with a few other radio buttons I also have a submit button to initiate the action:
<input type="submit" name="submit" value="submit">
Thanks in advance for any help.
Try the following block:
<input type="radio" name="Query" value="SELECT employees.name FROM employees, department WHERE employees.department_deptID=department.deptID AND department.departName='Information Technology'"> List all employees in a particular department (Information Technology).<br />
I have replaced the "
with '
at department.departName='Information Technology'
Note: This whole logic looks bad idea to me. You are passing the query from the browser which results in high risk. Also use mysqli_* functions and stop using mysql_* functions