$ _POST给出了未识别的索引错误

时间:2015-09-24 14:01:59

标签: php mysql ajax post

我正在制作一个ajax登录脚本,我的html代码如下:

<form class="form-container" action="login.php" method="POST">
  <div class="form-title"><h2>Sign up</h2></div>
  <div class="form-title">Name</div>
  <input class="form-field" type="text" name="username" /><br />
  <div class="form-title">Password</div>
  <input class="form-field" type="password" name="pass" /><br />
  <div class="submit-container">
    <input class="submit-button" type="submit" value="Submit" />
  </div>
</form>

我的php代码如下:

$client_username = $_POST["username"];
$client_password = $_POST["pass"]

当我运行代码时,我在wamp服务器中出现错误,在我的php代码中显示Unidentified Index。有什么问题,我该如何解决?

编辑:

我尝试过但却徒劳无功:

if(isset($_POST["username"]))
{
     $client_username = $_POST["username"];
}

if(isset($_POST["pass"]))
{
  $client_password = $_POST["pass"];
}


echo $client_username;

echo $client_password;

1 个答案:

答案 0 :(得分:1)

试试这个,只需使用isset()来检查POST变量

$client_username = "";
$client_password = "";

if(isset($_POST["username"]));
{
     $client_username = $_POST["username"];
}

if(isset($_POST["pass"]))
{
   $client_password = $_POST["pass"];
}