Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从html表单查询pgsql日期范围_Php_Html_Postgresql - Fatal编程技术网

Php 从html表单查询pgsql日期范围

Php 从html表单查询pgsql日期范围,php,html,postgresql,Php,Html,Postgresql,我正在尝试构建一个允许从pgsql数据库生成自定义报告的页面。在PHP中,我声明了变量$table、$datea和&datez。。。然后,我有一个html表单,用户可以在其中发布所选的表和查询变量的日期。但是,我收到一条错误消息(错误500页不工作,无法处理此请求)。有人能提供一些建议吗 $datea= $_POST["userDatea"]; $table= $_POST["userTable"]; $datez= $_POST["userDatez"]; if(isset($_POST['

我正在尝试构建一个允许从pgsql数据库生成自定义报告的页面。在PHP中,我声明了变量$table、$datea和&datez。。。然后,我有一个html表单,用户可以在其中发布所选的表和查询变量的日期。但是,我收到一条错误消息(错误500页不工作,无法处理此请求)。有人能提供一些建议吗

$datea= $_POST["userDatea"];
$table= $_POST["userTable"];
$datez= $_POST["userDatez"];

if(isset($_POST['submit'])
// Create connection
$conn = pg_connect("host=xx.xx.xx.xx port=xxxx dbname=fpscdb001 user=xxx password=xxxxxxxxxxxxxx");

// Check connection
if (!$conn) {
echo "Did not connect.\n";
exit;
}
$result = pg_query($conn, "SELECT *
FROM 
fpscdb001_ws_001.$table
WHERE 
$table.created_on BETWEEN '$datea' AND '$datez' AND
$table.soft_delete_id = '0';");

Form:
<form method="post" id="report" action="custom.php">
<div class="formitem" style="max-width: 200px;">
<p style="font-color: white" style="font-weight: 800px">Select a Table:</p>
<p><select name="table" class="form-control" id="userTable">
<option value="dispatch_1">Dispatch</option>
<option value="normal_usb__a_t">Inventory</option>
<option value="incident">Real Estate</option>
<option value="tech_support2">Tech-Support</option>
</select></p>
</div>
<div class="formitem" style="max-width: 200px" style="margin-bottom: 20px">
<p>FROM DATE</p> <input type="DATE" class="textarea" id="userDatea" style="height: 30px; border-radius: 5px;"><br><br>
<p>TO DATE</p> <input type="DATE" class="textarea" id="userDatez" style="height: 30px; border-radius: 5px;"><br><br>
</div>                          
<div style="padding-bottom: 120px">
<input type="submit" class="btn btn-small greyBtn light submit" value="Submit" style="max-width: 200px; max-height: 125px"> 
</div>
</form>
$datea=$\u POST[“userDatea”];
$table=$\u POST[“userTable”];
$datez=$_POST[“userDatez”];
如果(isset($_POST['submit']))
//创建连接
$conn=pg_connect(“主机=xx.xx.xx.xx端口=xxxx数据库名=fpscdb001用户=xxx密码=xxxxxxxxxxxxxxxxx”);
//检查连接
如果(!$conn){
echo“未连接。\n”;
出口
}
$result=pg_查询($conn,“选择*
从…起
fpscdb001_ws_001.$table
哪里
$table.created_位于“$datea”和“$datez”之间,并且
$table.soft_delete_id='0';”;
表格:

选择一个表格:

派遣 库存 房地产 技术支持

从日期开始 迄今为止
试试这个。 请参阅代码中的注释

<?php
    // show error messages
    ini_set('error_reporting', E_ALL);
    ini_set("display_errors", 1);

    $datea= $_POST["userDatea"];
    $table= $_POST["userTable"];
    $datez= $_POST["userDatez"];

    // You need to do all of this if and only if this is a post request
    // Also this method of detecting a post request is more consistent
    if( !empty($_SERVER['REQUEST_METHOD']) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'post')===0)  ) {
        // Create connection
        $conn = pg_connect("host=xx.xx.xx.xx port=xxxx dbname=fpscdb001 user=xxx password=xxxxxxxxxxxxxx");

        // Check connection
        if (!$conn) {
            echo "Did not connect.\n";
            exit;
        }

        $result = pg_query($conn,
            "SELECT *
            FROM 
            fpscdb001_ws_001.$table
            WHERE 
            $table.created_on BETWEEN '$datea' AND '$datez' AND
            $table.soft_delete_id = '0';"
        );


        if (!$result) {
            echo "Query failed\n";
            exit;
        }

        exit('Success?');
    }
?>
<!-- Make sure your HTML is well formed  -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Test</title>
</head>
<body>
Form:
<form method="post" id="report" action="custom.php">
    <div class="formitem" style="max-width: 200px;">
        <p style="font-color: white" style="font-weight: 800px">Select a Table:</p>
        <!-- The attribute name is used as the key for the $_POST array. Without a name the form control will not be submitted   -->
        <p><select name="userTable" class="form-control" id="userTable">
                <option value="dispatch_1">Dispatch</option>
                <option value="normal_usb__a_t">Inventory</option>
                <option value="incident">Real Estate</option>
                <option value="tech_support2">Tech-Support</option>
            </select></p>
    </div>
    <div class="formitem" style="max-width: 200px" style="margin-bottom: 20px">
        <!-- The attribute name is used as the key for the $_POST array. Without a name the form control will not be submitted   -->
        <p>FROM DATE</p> <input type="DATE" class="textarea" id="userDatea" name="userDatea" style="height: 30px; border-radius: 5px;"><br><br>
        <!-- The attribute name is used as the key for the $_POST array. Without a name the form control will not be submitted   -->
        <p>TO DATE</p> <input type="DATE" class="textarea" id="userDatez" name="userDatez"  style="height: 30px; border-radius: 5px;"><br><br>
    </div>
    <div style="padding-bottom: 120px">
        <input type="submit" class="btn btn-small greyBtn light submit" value="Submit" style="max-width: 200px; max-height: 125px">
    </div>
</form>
</body>
</html>

试验
表格:

选择一个表格:

派遣 库存 房地产 技术支持

从日期开始 迄今为止
用错误消息更新您的问题…页面不工作http error 500在/var/log/apache2/error.log中看到了什么?谢谢,尽管我得到了相同的回答。@KevMoe 500表示您有一个致命错误。请像Naton说的那样检查日志。@KevMoe也
dbname=fpscdb001
fpscdb001\ws\u 001不同e> 确保使用正确的数据库查询失败:错误:语法错误位于或接近““””第5行:。已在“”和“”之间创建^in/home2/rightme1/public\u html/networks/reports/customphp.php29@KevMoe您是否复制并粘贴了整个脚本,因为该错误意味着您没有获取post数据。如果您的html表单控件上有名称,并且您实际输入了一个值,那么它应该可以工作。