gpt4 book ai didi

php - 写入 CSV 时出错 - 警告 : fopen() [function. fopen]:文件名不能为空

转载 作者:行者123 更新时间:2023-11-29 14:40:41 27 4
gpt4 key购买 nike

在我的网站上,用户填写表格进行注册,然后该信息会添加到数据库中。我也试图将信息写入 CSV 文件。到目前为止我的代码给了我这个错误:

警告:fopen() [function.fopen]:第 122 行/home/content/m/a/t/matronryan/html/sendmail3.php 中的文件名不能为空

第 122 行:$fp = fopen($filename, "w");

我无法弄清楚问题出在哪里。代码如下:

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$stilldonate = $_POST['stilldonate']; // not required
$phone = $_POST['phone'];
$bid = $_POST['bid']; // required
$item = $_POST['item'];
$address1 = $_POST['address1']; // required
$address2 = $_POST['address2'];
$city = $_POST['city'];
$county = $_POST['county']; // required
$postcode = $_POST['postcode']; // required
$updated = $_POST['updated'];

include('db_functions.php');
connect_to_db();
$query="insert into auctionusers (firstname, lastname, address1, address2, city, county, postcode, email, phone, bid, stilldonate, item, updated) values ('$first_name', '$last_name', '$address1', '$address2', '$city', '$county', '$postcode', '$email_from', '$phone', '$bid', '$stilldonate', '$item', '$updated')";
$result=mysql_query($query);


$filename == 'auctionusers.csv';
$fp = fopen($filename, "w");

$res = mysql_query("SELECT * FROM auctionusers");

// fetch a row and write the column names out to the file
$row = mysql_fetch_assoc($res);
$line = "";
$comma = "";
foreach($row as $name => $value) {
$line .= $comma . '"' . str_replace('"', '""', $name) . '"';
$comma = ",";
}
$line .= "\n";
fputs($fp, $line);

// remove the result pointer back to the start
mysql_data_seek($res, 0);

// and loop through the actual data
while($row = mysql_fetch_assoc($res)) {

$line = "";
$comma = "";
foreach($row as $value) {
$line .= $comma . '"' . str_replace('"', '""', $value) . '"';
$comma = ",";
}
$line .= "\n";
fputs($fp, $line);

}

fclose($fp);

mysql_close();


header('location: index2.php?op=Thank You&id=bid');

}
?>

谁能看出问题所在吗?

最佳答案

更改:

$filename == 'auctionusers.csv';

致:

$filename = 'auctionusers.csv';

双等于对变量执行 bool 运算。您肯定错误地添加了一个额外的等号。

关于php - 写入 CSV 时出错 - 警告 : fopen() [function. fopen]:文件名不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8050168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com