0

我的表单有以下代码,但它似乎不起作用,在填写所有字段后查询不会插入。如果有人可以查看并帮助我纠正任何错误,我将不胜感激。表单的方法是post,动作是<?php echo $_SERVER['PHP_SELF'];?>。这是我在 PHP 中的第一个代码,所以在这里很新 谢谢。

<?php
  $counter=1;
  if (isset($_POST["post"])) {
    $gender= $_POST['gender'];
    $fname= $_POST['fname'];
    $lname= $_POST['lname'];
    $email= $_POST['email'];
    $fone= $_POST['fone'];
    $school= $_POST['skuul'];
    $other= $_POST['other'];
    $output_form=false;
    $is_error = false;

    if (empty($email)) {
      echo "Please enter your email or contact info. \n";
      $output_form = $is_error = true;
    }

    if (empty($lname)) {
      echo "Please enter your email or contact info. \n";
      $output_form= $is_error = true;
    }

    if (empty($fone)) {
      echo "Please enter your email or contact info. \n";
      $output_form= $is_error = true;
    }

    if (empty($fname)) {
      echo "Please enter your name. \n";
      $output_form= $is_error = true;
    }

    if ($output_form) { 
      $query= "INSERT INTO 'elect_conference' ('gender', 'fname', 'lname', 'phone',                                 'email', 'School', 'course', 'other')".
      "values ('$gender', '$fname', '$lname', '$fone', '$email', '$school', '$course', '$other');";
      $result = execute($query);
      echo '<article class="extra-wrap">'."Hello $name congratulations, you are the                                  number $counter member registered for the ELECT Conference.
      A confirmation will be sent to your email ($email) within five(5) hours.\n
      Thank you. And have a nice day.</artice>";
      $fname="";
      $lname="";
      $fone="";
      $email="";
      $fone="";
      $school="";
      $subject="";
      $counter++;
    } else {
      echo "Please ensure that all the fields are approprietly filled";}
    } else {
      $output_form=true;
    }
    if ($output_form) {
  ?>
  <body id="page2">
    <!--==============================header=================================-->
    <section id="content">
      <div class="pad">
        <div class="main">
          <article class="grid_9 suffix_1">
            <div class="form1">
              <div class="padding">
                <h4 class="border-bot2 img-indent-bot" align="center" style="color:#00C !important">
                  ELECT Conference <br/>Registration
                </h4>
                <form id="form" action="<?php echo $_SERVER['PHP_SELF']; ?>"               method="post"enctype="multipart/form-data">
                  <fieldset>
                    <div style="margin-left:90px !important;"><?php echo "$counter/500"; ?></div>
                    <div class="rowElem0">
                      <span class="radio">Personal Infomation:</span>
                      <span class="radio2">
                      <input type="radio" name="gender" value="Mr" checked>
                      <label class="ratio">Mr</label>
                      <input type="radio" name="gender" value="Mrs">
                      <label class="ratio">Ms</label>
                      <input type="radio" name="gender" value="Mrs">
                      <label class="ratio">Mrs</label>
                    </span>
                  </div>
                  <div class="rowElem">
                    <label><span class="input">First Name:</span></label>
                    <input type="text" name="fname" value="<?php echo $fname; ?>"/>
                  </div>
                  <div class="rowElem">
                    <label><span class="input">Last Name:</span></label>
                    <input type="text" name="lname" value="<?php echo $lname; ?>"/>
                  </div>
                  <div class="rowElem">
                    <label><span class="input">Phone:</span></label>
                    <input type="text" name="fone" value="<?php echo $fone; ?>"/>
                  </div>
                  <div class="rowElem">
                      <label><span class="input">E-mail:</span></label>
                      <input type="text" name="email" value="<?php echo $email; ?>"/>
                  </div>
                  <div class="rowElem1">
                    <input type="radio" name="graduate" id="chbox4" checked>
                    <strong><label class="check2">Graduate?</label></strong>
                  </div>
                  <div class="rowElem">
                    <label><span class="input">School:</span></label>
                    <input type="text" name="skuul" value="<?php echo $school; ?>"/>
                  </div>
                  <div class="rowElem">
                    <label><span class="input">Course:</span></label>
                    <input type="text" name="course" value="<?php echo $school; ?>"/>
                  </div>
                  <div class="rowElem1">
                    <input type="radio" name="other" id="chbox5">
                    <strong><label class="check2">Other</label></strong>
                    <label><span class="input">Specify:</span></label>
                    <input type="text" name="other" value="<?php echo $other; ?>"/>
                  </div>
                  <div class="buttons">
                    <input class="button" type="submit" value="Submit" />
                  </div>
                </fieldset>
              </form>
            </div>
          </div>
        </article>
      </div>
    </div>
  </div>
</section>
<script type="text/javascript"> Cufon.now(); </script>
</body>
<?php
}
?>
</html>
4

1 回答 1

-1

请显示表单代码,并在表单处理结果中具体说明。究竟是什么不起作用?

同时,这里有一些观察:

  1. $_POST您可以这样做,而不是一次分配每个元素:

    foreach ($_POST as $key=>$value) $$key = $value;

  2. *$output_form*并且*$is_error*总是具有相同的值,为什么要重复?

于 2013-06-09T04:57:17.430 回答