What does if(isset($_POST['btn-signup']))

2019-09-22 10:52发布

What does the if(isset($_POST['btn-signup']))line do? Im learning php. I have completed a few courses on the basics and now im learning through sample programs. This is the php section of a login form. Its obviously working fine but i still dont understand the use of $_POST very well.

<?php
session_start();
if(isset($_SESSION['userSession'])!="")
{
 header("Location: home.php");
}
include_once 'dbconnect.php';

if(isset($_POST['btn-signup']))
{
 $uname = $MySQLi_CON->real_escape_string(trim($_POST['user_name']));
 $email = $MySQLi_CON->real_escape_string(trim($_POST['user_email']));
 $upass = $MySQLi_CON->real_escape_string(trim($_POST['password']));

 $new_password = password_hash($upass, PASSWORD_DEFAULT);

 $check_email = $MySQLi_CON->query("SELECT email FROM users WHERE email='$email'");
 $count=$check_email->num_rows;

 if($count==0){


  $query = "INSERT INTO users(username,email,password) VALUES('$uname','$email','$new_password')";


  if($MySQLi_CON->query($query))
  {
   $msg = "<div class='alert alert-success'>
      <span class='glyphicon glyphicon-info-sign'></span> &nbsp; successfully registered !
     </div>";
  }
  else
  {
   $msg = "<div class='alert alert-danger'>
      <span class='glyphicon glyphicon-info-sign'></span> &nbsp; error while registering !
     </div>";
  }
 }
 else{


  $msg = "<div class='alert alert-danger'>
     <span class='glyphicon glyphicon-info-sign'></span> &nbsp; sorry email already taken !
    </div>";

 }

 $MySQLi_CON->close();

标签: php mysqli
1条回答
够拽才男人
2楼-- · 2019-09-22 11:18
if(isset($_POST['btn-signup']))

when a form is submitted to a php url via the http 'post' method , the named values in that form are added to $_POST with their respective names as keys. this line checks if the php document received a value named 'btn-signup'

the source form might contain something like

<input type="text" name="btn-signup" />
查看更多
登录 后发表回答