使用isset进行PHP表单验证($ _ POST [' name'])

时间:2017-09-16 23:23:22

标签: php html

罗宾尼克松的代码书:

if (isset($_POST['user'])) {
  $user = sanitizeString($_POST['user']);
  $pass = sanitizeString($_POST['pass']);
  if ($user == "" || $pass == "")
    $error = "Not all fields were entered<br><br>";
  else {
    $result = queryMysql("SELECT * FROM members WHERE user='$user'");
    if ($result - > num_rows)
      $error = "That username already exists<br><br>";
    else {
      queryMysql("INSERT INTO members VALUES('$user', '$pass')");
      die("<h4>Account created</h4>Please Log in.<br><br>");
    }
  }
}

为什么他在这里使用isset($ _ POST [&#39; user&#39;])? 为什么他不使用isset($ _ POST [&#39;提交&#39;]而不是?

1 个答案:

答案 0 :(得分:0)

该代码已经缺少结束括号。

<?php
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
$error = "Not all fields were entered<br><br>";
else
{
$result = queryMysql("SELECT * FROM members WHERE user='$user'");
if ($result->num_rows)
$error = "That username already exists<br><br>";
else
{
queryMysql("INSERT INTO members VALUES('$user', '$pass')");
die("<h4>Account created</h4>Please Log in.<br><br>");
 } 
}
}
?>

如果设置了POST用户,代码现在接受了。或者如果在你的html表单字段上实现代码提交!如果你需要POST提交检查..所以我想做什么?请告知我可以根据需要进行修改。