-7

我正在尝试将我的表单信息插入到已经创建的数据库中。到目前为止,我有:

    <form action="insert.php" method="post">
      Username:
      Password:
      Confirm Password:
      <input type="submit">
      if loops {
        send alert and return back to form page; }
    </form>

我的问题是:使用此代码,如果激活了 if 循环,用户信息是否仍会发送到数据库文件,或者在每个 if 循环之后我是否需要退出语句?(如果激活了 if 循环,我不希望发送任何信息)。

谢谢

4

2 回答 2

0

您还可以在客户端验证您的表单,它更快并减少服务器负载:

 <form name="myForm" action="insert.php" method="post"  onsubmit="return validateForm()>
      Username:
      Password:
      Confirm Password:
      <input type="submit">
    </form>

并编写一个 javascript 来验证您的表单:

<script type="text/javaScript">
function validateForm()
{
  //Here will be your validation logic
  //if input doesn't meet your requirement then return false 
  var x=document.forms["myForm"]["email"].value;
  if(x is not an email address) 
  return false;
  }
}
</script>
于 2013-07-04T10:13:45.880 回答
0

您需要inputs在表格上:

 <form action="insert.php" method="post">
       Username: <input type="text" name="username">
       Password: <input type="password" name="password"> 
       Confirm Password: <input type="password" name="confirm">
       <input type="submit" name="submit">
     </form>

然后上insert.php

if (isset($_POST['submit'])){
  $Error = 0;
 if (!isset($_POST['username'])){
  $Error++;
 }
 if (!isset($_POST['password'])){
  $Error++;
 }
 if (!isset($_POST['confirm'])){
  $Error++;
 }

 if ($Error > 0){
  echo "Error in HTML Validation";
  exit; 
 }


// continue post verification here. 

}
于 2013-07-04T09:54:49.673 回答