将HTML表单中的脱机数据存储到CSV

时间:2013-08-01 11:15:47

标签: php javascript

我在HTML上有一个简单的表单,我想让它在线和离线工作。我正在尝试将数据发布到CSV文件中,但它似乎对我不起作用。

这是我的HTML代码:

<form>
  <label>Insert your name</label>
  <input type="text" name="txtName" />
  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
  <input type="radio" name="choose" value="I agree with the terms and condtions">I agree with the terms and condtions
  <input type="radio" name="choose1" value="I disagree with the terms and condtions">I disagree with the terms and condtions
  <input type="submit" name="formSubmit" value="Submit" onclick="check()">
  </p>
</form>

和我的php:

if($_POST['formSubmit'] == "Submit")
{
    $errorMessage = "";
    if(empty($_POST['txtName']))
    {
        $errorMessage .= "<li>Doh, You forgot to enter your name!</li>";
    }
    if(empty($_POST['choose']))
    {
        $errorMessage .= "<li>You must agree to the terms and conditions</li>";
    }
    if(empty($_POST['choose1'])
    {
        $errorMessage = "<li>You must agree to the terms and conditions</li>";
    }
    $varName = $_POST['txtName'];
    $varChoose = $_POST['choose'];
    $varChoose1= $_POST['choose1'];
    $fs = fopen("stelios.csv","a");
    fwrite($fs,$varName . ", " . $varChoose . "," . $varChoose1 . "\n");
    fclose($fs);
    header("Location: Test.html");
    exit;
}

另外,PHP是离线存储的好方法吗?我在考虑FileSystem,但它只在IE上兼容。感谢

0 个答案:

没有答案