从PHP表单获取用户输入并粘贴到csv文件中

时间:2015-01-15 13:14:01

标签: php forms csv web-applications spreadsheet

我有许多php表单和一个csv文件来存储所有内容.csv文件已经包含现有数据。我需要做以下事情: 当按下提交按钮时,打开csv文件并检查特定字段是否为空(参考编号只是将表单链接在一起的一种方式,因为每个表单由另一个人完成)。 如果是粘贴第一个字段 然后继续前进到下一个,依此类推 然后,当在另一个表单上按下提交时,检查以找到匹配并粘贴每个单元格中的值的引用号。 该行将保持不变,但每列的列都是特定于每个表单的,例如,我有B E和F表格1 A D G表格2,依此类推。

有谁能举例说明如何做到这一点? 感谢

    <html>
    <head><title>Network Design Request</title></head>
    <title>Design Request</title>     

      <form action="exec-data.php" method="POST">
      <fieldset align="left">
     <legend>Executive Sponsor Form</legend>
      <p><i>To be completed by the executive sponsor</i></p>
      <table>
    <tr>
    <td>Refrence Number:</td>
    <td><?php $Ref = new DateTime();
    echo $Ref->format('U') . "\n";
    ?>
    </td></tr>
      <tr>
       <td>Name:</td><td><input type="text" name="SNAME" size="40" /></td>
      </tr>

      <tr>
       <td>Position:</td><td><input type="text" name="SPOSITION" size="40" /></td>
      </tr>

      <tr>
       <td>Telephone Number:</td><td><input type="text" name="SNUMBER" size="40" maxlength="11" /></td>
      </tr>

      <tr>
       <td>Email Address:</td><td><input type="email" name="SEMAIL" size="40" /></td>
      </tr>

      <tr>
       <td>Budget Available:</td><td><input type="checkbox" /><input type="text" name="BUDGET" size="37" maxlength="6" placeholder="2014 budget submission code" /></td>
      </tr>

 <tr>
   <td>Aligned to which<br>priority:</td><td><input type="text" name="PRIORITIES" size="40" /></td>
  </tr>

  </form>

这是我目前的形式和代码之一:

    <?php

$inputFileType = 'csv';
$inputFileName = '\Documents\Network Design Project\Notepad++ndr_db.csv';
$sheetname = '2015 Jan';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setLoadSheetsOnly($sheetname);
$objReader = $objReader->load($inputFileName);

$Refrow = 1
$Refcol = 2

foreach ($data as $Refrow){
    if ($Refrow is_null){$Refrow++}
    else ($_POST['$Ref'] )
}

$Exec_col = 5
$Exec_row = 1
foreach ($data as $Exec_row){
    if ($Exec_row is_null){$Exec_row++}
    else ($_POST['SNAME'] )
}

?>

1 个答案:

答案 0 :(得分:0)

你应该使用fputcsv。 从php.net阅读手册

http://php.net/manual/en/function.fputcsv.php

相关问题