注册时检查错误


Checking Errors when signing up

我在我的html中添加了一个动态选择器,在注册时选择性别和国家,现在的问题是我如何使用IF和Else简手来检查用户是否选择了这两个,以便注册完成,

这是我添加的选择器

<div>Gender:</div>
    <select id="gender" onfocus="emptyElement('status')">
      <option value=""></option>
      <option value="m">Male</option>
      <option value="f">Female</option>
    </select>
    <div>Country:</div>
    <select id="country" onfocus="emptyElement('status')">
      <?php include_once("country_list.php"); ?>
    </select>
    <div>

您必须在表单输入中添加一个name属性。

<select id="gender" name="gender" onfocus="emptyElement('status')">
<select id="country" name="country" onfocus="emptyElement('status')">

您可以检查它是否已设置。

if(!isset($_POST['gender'])) 
{
  //Do what you need to if it is not set (such as a redirect)
}
if(!isset($_POST['country'])) 
{
  //Do what you need to if it is not set (such as a redirect)
}

希望对你有帮助。