从内部单选按钮中检索查询结果

时间:2013-11-08 02:49:54

标签: php mysql sql forms

我试图通过此单选按钮回显或打印出查询结果:

<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 />

我目前使用的代码是:

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 "\r\n";
}
    }

除了一些其他单选按钮,我还有一个提交按钮来启动操作:

<input type="submit" name="submit" value="submit">

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

尝试以下块:

<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 />

我已在"

'替换为department.departName='Information Technology'

注意:这整个逻辑看起来对我不好。您正在从浏览器传递查询,这会导致高风险。还可以使用mysqli_ *函数并停止使用mysql_ *函数