Php 将脱机数据从HTML表单存储到CSV
我有一个简单的HTML表单,我想让它在线和离线工作。我试图将数据发布到CSV文件中,但它似乎对我不起作用 这是我的HTML代码:Php 将脱机数据从HTML表单存储到CSV,php,javascript,Php,Javascript,我有一个简单的HTML表单,我想让它在线和离线工作。我试图将数据发布到CSV文件中,但它似乎对我不起作用 这是我的HTML代码: <form> <label>Insert your name</label> <input type="text" name="txtName" />         <input typ
<form>
<label>Insert your name</label>
<input type="text" name="txtName" />
       
<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>
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:
<form>
<label>Insert your name</label>
<input type="text" name="txtName" />
       
<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>
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;
}
if($\u POST['formSubmit']==“Submit”)
{
$errorMessage=“”;
if(空($_POST['txtName']))
{
$errorMessage.=“Doh,你忘了输入你的名字! ”;
}
if(空($_POST['choose']))
{
$errorMessage.=“您必须同意条款和条件” ”;
}
if(空($\u POST['choose1']))
{
$errorMessage=“您必须同意条款和条件” ;
}
$varName=$_POST['txtName'];
$varChoose=$_POST['choose'];
$varChoose1=$\u POST['choose1'];
$fs=fopen(“stelios.csv”,“a”);
fwrite($fs,$varName.”,“$varChoose.”,“$varChoose1.”\n”);
现金流量表(fs);
标题(“位置:Test.html”);
出口
}
另外,PHP是离线存储的好方法吗?我在考虑文件系统,但它只在IE上兼容。谢谢PHP是一种服务器端编程语言。如果用户离线,服务器端就不存在。那么有没有办法将mt数据离线存储在CSV文件中?谢谢,因为JavaScript不能写入文件系统。你可以我会改用HTML5本地存储。但那只是一个键值存储,不是csv,所以用户无法打开它。Cookie呢?我知道它的局限性,但我想知道它是否可能是一个临时解决方案文件系统api可能可以使用。我想这些文件也不能“正常方式”访问。