[英]Php save data to .csv and then redirect
Like the title says, I am trying to make a php script that saves the data to a csv then redirects them to another url on my site. 就像标题所说的那样,我正在尝试制作一个php脚本,将数据保存到csv,然后将它们重定向到我的网站上的另一个URL。 All that is happening is when I hit the submit button I get an error on saying it cannot handle the request.
发生的一切是,当我按下“提交”按钮时,我收到一条错误消息,说它无法处理请求。
This is my form 这是我的表格
<form action="submit.php" method="post">
<h1 style="text-align: center;">Register</h1><br>
<fieldset>
<legend>Your registration info</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="user_name" required="">
<label for="mail">Email:</label>
<input type="email" id="mail" name="user_email" required="">
<label for="phone">Phone:</label>
<input type="phone" id="phone" name="phone">
<label for="guest">Guest or Spouse:</label>
<input type="text" id="gsname" name="gsname">
<label>Date Attending:</label>
<input type="radio" id="tuesday" value="tuesday" name="date"><label
for="tuesday" class="light">Tuesday, May #, 2018 10 AM - 11:30 AM</label>
<br>
<input type="radio" id="thursday" value="thursday" name="date"><label
for="thursday" class="light">Thursday, May #, 2018 10 AM - 11:30 AM</label>
</fieldset>
<button type="submit" name="submit">Register Now</button>
</form>
This is my php script. 这是我的PHP脚本。
if (isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$name = $_POST['user_name'];
$email = $_POST['user_email'];
$phone = $_POST['phone'];
$gsname = $_POST['gsname'];
$date = $POST['date'];
$open = fopen("formdata.csv", "a");
$csvData = $name. "," $email. "," $phone. "," $gsname. "," $date. "n";
fwrite($open,$csvData)
fclose($open)
#if($name !=''&& $email !=''&& $phone !=''&& $gsname
// To redirect form on a particular page
header("Location:https://www.google.com/");
}
else (
header("Location:https://www.charter.com");
)
?>
Can anyone give me an idea where I am messing up? 谁能给我个主意呢? I know data validation is important, but if I am using it on the form itself, do I need to validate it here?
我知道数据验证很重要,但是如果我在表单本身上使用它,是否需要在此处进行验证?
A few things that I would try: 我会尝试的几件事:
$date = $_POST['date'];
$date = $_POST['date'];
$name . "," . $email . "," . $phone . "," . $gsname . "," . $date . "\\n";
$name . "," . $email . "," . $phone . "," . $gsname . "," . $date . "\\n";
$name . "," . $email . "," . $phone . "," . $gsname . "," . $date . "\\n";
fputcsv()
as well. fputcsv()
。 Although it's not mandatory, it's highly recommended that you do server-side validation. 尽管不是强制性的,但强烈建议您进行服务器端验证。 Never assume the data you are receiving is the way you want it.
永远不要以为要接收的数据就是您想要的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.