if语句不起作用并且不显示echo

时间:2014-02-08 15:28:04

标签: php html

 <?php
  $reg = @$_POST['reg'];
  $fn        =   "";
  $ln        =   "";
  $un        =   "";
  $em        =   ""; 
  $pswd      =   ""; 
  $d         =   "";
  $u_check   =   ""; 

  $fn   =   strip_tags(@$_POST['fname']);
  $ln   =   strip_tags(@$_POST['lname']);
  $un   =   strip_tags(@$_POST['uname']);
  $em   =   strip_tags(@$_POST['email']); 
  $pswd =   strip_tags(@$_POST[ 'pass']);  
  $d = date('Y-m-d');

  if ($reg) {
      echo 'test';
  }
 ?>
<div class="form">
    <input class="Firstname"  type="text"     name="fname"       placeholder="Fisrt name">
    <input class="Lastname"   type="text"     name="lname"       placeholder="Last name">
    <input class="username"   type="text"     name="uname"       placeholder="Usename">
    <input class="email"      type="email"    name="email"       placeholder="Email">
    <input class="pass"       type="password" name="pass"        placeholder="Password">
    <input class="submit"     type="submit"   name="reg"         value="Sign In">
</div>

这里的问题在哪里?当我点击reg按钮时它没有显示回声,请问这里有什么问题。即使我添加其他if语句,它也不起作用。

2 个答案:

答案 0 :(得分:4)

您需要一个表单来提交数据

<form method="POST">
 ... your form element goes here
</form>

答案 1 :(得分:1)

试试这个,您可以使用isset()功能检查$_POST['reg']

if(isset($_POST['reg'])){
  $fn   =   strip_tags($_POST['fname']);
  $ln   =   strip_tags($_POST['lname']);
  $un   =   strip_tags($_POST['uname']);
  $em   =   strip_tags($_POST['email']); 
  $pswd =   strip_tags($_POST['pass']);  
  $d = date('Y-m-d');

 echo 'test';
}

HTML:

<form method="POST">
  your html content
</form>