如果声明里面的isset函数不起作用

时间:2015-07-23 11:25:27

标签: php

我正在尝试使用php验证我的表单,我正在使用isset函数来检查是否已单击提交按钮。当我单击提交按钮时,isset函数内的代码不会执行。

//html


    <div style="width:800px; margin:0px auto 0px auto;">
       <table>
           <tr>
            <td width ="60%" valign="top">
             <h2>join to find friends today</h2>
            </td>

            <td width ="40%" valign="top">
              <h2>Sign up below</h2>

              <form action ="" method"POST">
              <input type="text" name="fname" size ="25"                     placeholder="firstname" /><br/><br/>
              <input type="text" name="lname" size ="25" placeholder="lastname" /><br/><br/>
              <input type="text" name="username" size ="25" placeholder="username"/><br/><br/>
              <input type="text" name="email" size ="25" placeholder="email"/><br/><br/>
              <input type="text" name="email2" size ="25" placeholder="confirm email"/><br/><br/>
              <input type="text" name="password" size ="25" placeholder="password"/><br/><br/>
              <input type="text" name="password2" size ="25" placeholder="confirm password"/><br/><br/>
              <input type="submit" name="reg" value="sign up">

              </form>

            </td>
           </tr>

       </table> 

//php code 

<?php


//declaring variables to prevent errors
$fn = ""; //First Name
$ln = ""; //Last Name
$un = ""; //Username
$em = ""; //Email  
$em2 = ""; //Email 2
$pswd = ""; //Password
$pswd2 = ""; // Password 2
$d = ""; // Sign up Date
$u_check = ""; // Check if username exists
$error ="";

  if (isset($_POST['reg'])) {

//registration form
$fn = strip_tags($_POST['fname']);
$ln = strip_tags($_POST['lname']);
$un = strip_tags($_POST['username']);
$em = strip_tags($_POST['email']);
$em2 = strip_tags($_POST['email2']);
$pswd = strip_tags($_POST['password']);
$pswd2 = strip_tags($_POST['password2']);
$d = date("Y-m-d"); // Year - Month - Day


if(empty($fn)){

 echo 'empty';

 } 
 }
 ?>

1 个答案:

答案 0 :(得分:0)

您忘记了=代码中的<form>

替换

<form action ="" method"POST">

<form action="" method="post">

它应该有用。