Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.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不返回用于显示的变量_Php - Fatal编程技术网

php不返回用于显示的变量

php不返回用于显示的变量,php,Php,我有一个html/php,可以查询数据库并将结果下载到csv文件中。那部分很好用。但是,我想在html页面的文本框中显示变量$message的文本。如果我不做fputcsv部分,它会工作。但是如果文件被下载,我就无法显示它。感谢您的帮助 <?php include('members.db.inc.php'); $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if(isset($_POST['Info_Verify'

我有一个html/php,可以查询数据库并将结果下载到csv文件中。那部分很好用。但是,我想在html页面的文本框中显示变量$message的文本。如果我不做fputcsv部分,它会工作。但是如果文件被下载,我就无法显示它。感谢您的帮助

<?php 

include('members.db.inc.php');

$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if(isset($_POST['Info_Verify'])){
$message1="Export Information Verification.";
ExportFile ("Information_Verification");
$message = $message1;
}

if(isset($_POST['Members'])){
$message="Export Member Import List.";
ExportFile ("Member_Import_List");
}
if(isset($_POST['GMail'])){
$message="Export Gmail Import List.";
ExportFile ("GMail_Import_List");
}


function ExportFile($temp) {

//echo $temp;
$error = 0;
$filename = $temp . ".csv";
$sql = sprintf("Select * from " . $temp);
//print $sql . '<br>';

$result = DBi::$conn->query($sql);
if (!$result) die('Couldn\'t fetch records'. DBi::$conn->connect_error) . '<br>';

$headers = $result->fetch_fields();

foreach($headers as $header) {
    $head[] = $header->name;
}

$fp = fopen('php://output', 'w');
if ($fp && $result) {
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename=' . $filename);
    header('Pragma: no-cache');
    header('Expires: 0');
    fputcsv($fp, array_values($head)); 
    while ($row = $result->fetch_array(MYSQLI_NUM)) {
        fputcsv($fp, array_values($row));
        }
    fclose($fp);
    exit;
    }
}    


?>
<html>
<head>
<title>Export Information</title>
<style type="text/css">
.auto-style1 {
border: 1px solid #000000;
text-align: center;
}
.auto-style2 {
border: 3px solid #000000;
}
.auto-style3 {
border: 1px solid #000000;
}
</style>
</head>
<body>
<form name="Export_Form" action="<?php echo $_SERVER['PHP_SELF']; ?>"     method=post>
<input type="text" name="txt" value="<?php if(isset($message)){ echo $message;}?>" style="width: 688px" ><br>
<br>&nbsp;<br>
<table style="width: 100%" class="auto-style2">
    <tr>
        <td class="auto-style1" style="width: 208px">
<input type="submit" name="Info_Verify" value="Information Verification"></td>
        <td class="auto-style3">
        House_Number,Street_Name,Member_Name,Phone_Number_1,Phone_Number_2,Zip_Code,Email1,EMail2,Communication_Code,Hide_Information</td>
    </tr>
    <tr>
        <td class="auto-style1" style="width: 208px">&nbsp;</td>
        <td class="auto-style3">&nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style1" style="width: 208px">
<input type="submit" name="Members" value="Members" ></td>
        <td class="auto-style3">"Home Address",Name,"Home Phone","Home Phone 
        2","E-Mail Address","E-Mail 2 Address",Categories"</td>
    </tr>
    <tr>
        <td class="auto-style1" style="width: 208px">&nbsp;</td>
        <td class="auto-style3">&nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style1" style="width: 208px">
<input type="submit" name="GMail" value="GMail Export" ></td>
        <td class="auto-style3">Name,"E-mail Address","E-mail 2 
        Address",Categories</td>
    </tr>
</table>
<br>&nbsp;
</form>
</body>
</html>

出口信息
.auto-style1{
边框:1px实心#000000;
文本对齐:居中;
}
.auto-style2{
边框:3px实心#000000;
}
.自动样式3{
边框:1px实心#000000;
}

您可以输出csv文件,也可以输出html,但不能同时输出两者。我想可能是这样。在写入文件后,是否可以将头更改回原来的位置,以便在保存文件后,if将输出为html?不幸的是,http响应只能有一种内容类型。您需要使用两步流程