我有一种情况,我想使用php文件“query.php”来查看$_POST
或$_GET
值作为MySQL查询。它看起来像这样:PHP - 将GET变量作为路径发送并包含/需要语句
<?php
//verify data has been sent via POST or GET and set strings
//find supplied table name
if(isset($_POST['tblName'])){
$strSuppliedTableName = $_POST['tblName'];
}
if(isset($_GET['tblName'])){
$strSuppliedTableName = $_GET['tblName'];
}
else{
$strSuppliedTableName = 'roles';
}
//find supplied field name or default to all fields in the table
if(isset($_POST['fieldName'])){
$strSuppliedFieldName = $_POST['fieldName'];
}
else if(isset($_GET['fieldName'])){
$strSuppliedFieldName = $_GET['fieldName'];
}
else{
$strSuppliedFieldName = '*';
}
//query db
$query = 'SELECT ' . $strSuppliedFieldName . ' FROM ' . $strSuppliedTableName;
$results = mysql_query($query) or die(mysql_error());
?>
在此之后,我想包括在将管理的结果另一个文件这个文件“query.php”。我试图尽可能模块化。
<?php
require_once("query.php?tblName=classes");
......... (while loop, yadi yadi
不过,我收到了一个错误:
Warning: require_once(query.php?tblName=classes) [function.require-once]: failed to open stream: No such file or directory
它是不能接受通过GET值的包含文件? PHP不会处理这个?
我有一个偷偷摸摸的怀疑,如果你在一个页面上包含query.php文件,并尝试引用“获取”变量,PHP实际上会查找您当前所在页面的网址而不是query.php。你可以做的一件事就是设置页面中的变量,调用query.php上面的“include”query.php'“行,然后引用query.php中的所有变量。 – MoarCodePlz