我在网上发现了一些教程和一些免费代码,并试图制作这个投票页面,但投票没有提交,页面也没有被重定向。我做错了什么?我如何解决它?我试了几个小时,但我无法得到它。这是代码,但真实姓名替换为John Doe。
<?php
if($_POST['formSubmit'] == "Submit")
{
$errorMessage = "";
if(empty($_POST['varVote']))
{
$errorMessage .= "<li>error</li>";
}
$varVote = $_POST['varVote'];
if(empty($errorMessage))
{
$fs = fopen("doe.csv","a");
fwrite($fs,$varName . ", \n");
fclose($fs);
header("Location: thank.htm");
exit;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Doe</title>
<style type="text/css">
body,td,th {
font-size: 24pt;
color: #FFFFFF;
font-family: Verdana, Geneva, sans-serif;
}
body {
background-color: #0000DD;
}
</style>
<meta name = "viewport" content = "width=device-width">
<script language="javascript" src="cookie.js">
</script>
</head>
<body bgcolor="#0000DD" onload="CheckForCookie ();">
<center>Are you sure you want to cast a vote for John Doe? You can only vote once!
<form id="form1" name="form1" method="post" action="aguire.php">
<p>
<label for="Doe"></label>
</p>
<p>
<input name="varVote" type="radio" value="1" checked="checked" style="display:none;" />
</p>
<p></p>
<p><a href="javascript:history.go(-1)"><img src="no.png" width="174"
border="0" align="middle" /></a>
<style>
input.btn {
background-image: url(yes.png);
background-repeat: no-repeat;
color: #FFFFFF;
font-size: 0px;
height: 41px;
width: 174px;
border: 0px;
cursor: pointer;
background-color: #000000;
}
</style>
<input name="formSubmit" type="submit" class="btn" value="submit" />
</p>
</form>
<p> </p>
<p><a href="thank.htm"><img src="skip.png" width="221" height="62" alt="skip" /></a></p>
</body></center>
<p> </p>
<center><p> </p>
<p> </p></center>
</body>
</html>
答案 0 :(得分:0)
你的if条件无法进入php块
if($_POST['formSubmit'] == "submit")
答案 1 :(得分:0)
你错过了一些事情:
第1行
if($_POST && $_POST['formSubmit'] == "submit")
提交按钮值等于“提交”而不是“提交”
第18行
fwrite($fs,$varVote . ", \n");
第13行设置的变量名是“$ varVote”而不是“$ varName”
答案 2 :(得分:0)
你在php代码中给出了错误的名字。
试试吧
<?php
if ($_POST['formSubmit'] == "submit" )
{
inner block;
//ETC.........
}
?>