0

我在网上找到了一些教程和一些免费代码,并试图制作这个投票页面,但没有提交投票并且页面没有被重定向。我做错了什么?我如何解决它?我尝试了几个小时,但我无法得到它。这是代码,但用 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>&nbsp;</p>
<p><a href="thank.htm"><img src="skip.png" width="221" height="62" alt="skip" /></a></p>
</body></center>
<p>&nbsp;</p>
<center><p>&nbsp;</p>
<p>&nbsp;</p></center>
</body>
</html>
4

3 回答 3

0

您的 if 条件无法进入 php 块

if($_POST['formSubmit'] == "submit")
于 2012-11-21T04:50:26.940 回答
0

你错过了一些事情:

第 1 行

if($_POST && $_POST['formSubmit'] == "submit")

提交按钮值等于“提交”而不是“提交”

第 18 行

fwrite($fs,$varVote . ", \n");

第 13 行设置的变量名称是“$varVote”而不是“$varName”

于 2012-11-21T04:53:18.533 回答
0

您在 php 代码中给出了错误的名称。

试试看

<?php 
     if ($_POST['formSubmit'] == "submit" )
     {
         inner block;
         //ETC.........
     }
?>
于 2012-11-21T04:58:17.250 回答