0

我有一个简单的 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 是离线存储的好方法吗?我在考虑文件系统,但它只在 IE 上兼容。谢谢

4

0 回答 0