dqe9657 2017-07-14 15:05
浏览 31
已采纳

内爆功能突然停止工作

This was working perfectly... I made some adjustments to the where clause of the select statement on the form from which the post is sourced and now it is no longer working. Any idea why I am suddenly getting an implode error?

Warning: implode() [function.implode]: Invalid arguments passed on line 9

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

$datea= $_POST["userDatea"];
$media= $_POST["userMedia"];
$datez= $_POST["userDatez"];
$media_names = "'".implode( "%','", $media)."%'";


//var_dump($media_names);

if( !empty($_SERVER['REQUEST_METHOD']) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'post')===0)  ) {
// Create connection
$conn = pg_connect("dbconnection info");

// Check connection
if (!$conn) {
echo "Did not connect.
";
exit;
}
$result = pg_query($conn,
"SELECT
date (b.starttime),
Count(b.starttime) as Plays,
Count(distinct(b.playerid)) as Stores

FROM
public.billing b,
public.medias m,
public.players p

WHERE
b.mediaitemid = m.id and
p.id = b.playerid and
m.name LIKE any (array[$media_names]) and
b.starttime >= date('$datea') and 
b.starttime < date('$datez')+1 and
m.startdate >  '2015-01-01'

GROUP BY
date (b.starttime)

ORDER BY
date (b.starttime);");

if (!$result) {
  echo "Query failed.
";

  exit;
}

 $num_fields = pg_num_fields($result);
    $headers = array();

    for ($i = 0; $i < $num_fields; $i++) 
    {
        $headers[] = pg_field_name($result , $i);
    }

    $fp = fopen('php://output', 'w');
    if ($fp && $result)
    {
            header('Content-Type: text/csv');
            header('Content-Disposition: attachment; filename="customreport.csv"');
            header('Pragma: no-cache');
            header('Expires: 0');
            fputcsv($fp, $headers);

            while ($row = pg_fetch_row($result)) 
            {
                 fputcsv($fp, array_values($row));
            }
            die;

}
        exit('It works');
    }
?>

Here is the source of the post:

<select multiple name="userMedia" class="form-control" id="userMedia[]" style="height:350px;">
 <?php

$conn = pg_connect("db connection");

if (!$conn) {
echo "Did not connect.
";
exit;
}
$sql = "SELECT 
        m.name
        FROM 
        public.medias m
        where 
        date(m.enddate) >= date(now()) - interval '183 days' and
        date(m.startdate) > '2015-01-01' and
        m.enddate != ''

        UNION ALL

        SELECT 
        m.name
        FROM 
        public.medias m
        where 
        m.enddate = '' and
        date(m.startdate) > '2015-01-01';";
$rs = pg_query($conn, $sql);


if (pg_num_rows($rs) > 0) {
// output data of each row
while($row = pg_fetch_assoc($rs)) {
$menu .= "<option value=".$row['name'].">" . $row['name']. "</option>";
}
}

echo $menu;

pg_close($conn); 

?> 
</select></p>
  • 写回答

1条回答 默认 最新

  • dt3358 2017-07-14 15:18
    关注

    Since the first argument you pass to implode() is a string (the "glue"), it expects the second argument to be an array.

    When $media (initialized using $_POST["userMedia"]) is not an array, implode() triggers the warning and returns NULL instead of the string you expect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 MATLAB四叉树处理长方形tif文件
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了