我是php的初学者,并且有以下代码从表单中获取值并将其作为数组插入到csv文件中
PHP:
if(isset($_GET['submitted'])){
$csvData = [$_GET["contract"],$_GET["article"],$_GET["specs"]];
$fp = fopen("order.csv","a");
if($fp) {
fputcsv($fp,$csvData); // Write information to the file
fclose($fp); // Close the file
}
}
HTML:
<form action="add.php" method="GET" >
<label class="wsite-form-label" >Contract No <span class="form-required">*</span></label>
<div class="wsite-form-input-container">
<input name="contract" id='contract'>
</div>
<label class="wsite-form-label" >Article <span class="form-required">*</span></label>
<div class="wsite-form-input-container">
<input name="article">
</div>
<label class="wsite-form-label"> SPECS<span class="form-required">*</span></label>
<input name="specs">
<button type='submit' name="submitted" value="true" >Submit </button>
</form>
尝试了get和post但仍然无法将插入的值添加到我的php中。请帮忙。
答案 0 :(得分:0)
您可以这样检查:
if(!empty($_GET["contract"]) && !empty($_GET["article"]) && !empty($_GET["specs"])){
$csvData = array($_GET["contract"],$_GET["article"],$_GET["specs"]);
$fp = fopen("order.csv","a");
if($fp) {
fputcsv($fp,$csvData); // Write information to the file
fclose($fp); // Close the file
}
}
答案 1 :(得分:0)
这是代码
<?php
if(isset($_GET['submitted']))
{
$csvData = array($_GET["contract"],$_GET["article"],$_GET["specs"]);
$fp = fopen("order.csv","a");
if($fp)
fputcsv($fp,$csvData);
file fclose($fp); // Close the file
}
?>
<html>
<head>
<title>dfsdfdsdfsdfs</title>
</head>
<body>
<form action="test.php" method="GET" >
/* Your Form */
</form>
</body>
</html>
答案 2 :(得分:0)