Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP表单处理和验证不起作用_Php_Forms_Validation_Processing - Fatal编程技术网

PHP表单处理和验证不起作用

PHP表单处理和验证不起作用,php,forms,validation,processing,Php,Forms,Validation,Processing,我的表单有下面的代码,它似乎不起作用,在填写完所有字段后查询不会插入。如果有人能看一下,帮我改正错误,我会非常感激的。表单的方法是post,操作是。这是我在PHP中的第一个代码,非常新,谢谢 <?php $counter=1; if (isset($_POST["post"])) { $gender= $_POST['gender']; $fname= $_POST['fname']; $lname= $_POST['lname']; $email=

我的表单有下面的代码,它似乎不起作用,在填写完所有字段后查询不会插入。如果有人能看一下,帮我改正错误,我会非常感激的。表单的方法是post,操作是
。这是我在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>

选举会议
登记
请显示表格代码,并在表格处理结果中具体说明。到底是什么不起作用

同时,以下是一些观察结果:

  • 您可以执行以下操作,而不是一次分配每个
    $\u POST
    元素:

    foreach($\发布为$key=>$value)$$key=$value

  • *$output\u form*
    *$is\u error*
    始终具有相同的值,为什么重复


  • 您的“$query=“INSERT INTO'elect_conference”…”代码严重混乱…在编写问题时可能会出现一些明显的错误;例如,
    $query
    字符串定义中有一些值在分号(
    ,$other');”之后重复电子邮件“,”学校“
    等);您的标签
    是用
    标签“关闭”的,您有
    在这里输入代码
    在不同的地方。。。请尽你所能解决问题,并详细告诉我们哪些不适合你(而不仅仅是“它不适合你”)。你的
    your
    doing
    foreach($\u POST as$key=>$value)$$key=$value可能很危险。如果将其添加到当前代码中,我可以在页面上定制帖子,并以
    alert(“您被劫持”)的形式传递计数器,javascript将在页面上运行。这就是所谓的跨站点脚本,这是一个禁忌