title: Birthdate + Gender calculations using identity Number - PHP/ Html/MySqli
body: <p>I am a new, "trying to be"  PHP Html and MySqli programmer coming from Ms Access and VB background. Can somebody please assist,  as I am stuck and sweating with these calculations.</p>
  
  <p>Example Identity number = 63021854485519</p>
  
  <ul>
  <li>The Birthdate from this =  dd/mm/yyyy = 18/02/1963</li>
  <li>The 7th digit indicates male or female ie 0-4 = female and 5-9 = male , So </li>
  <li>this person's Id No indicates its a Male as 7th digit is 5 (between 5-9)</li>
  </ul>
  
  <p>In VB to calculate birthdate from ID No I use ---> <code>DOB=Mid([idno],5,2) &amp; "/" &amp; Mid([idno],3,2) &amp; "/" &amp; Mid([idno],1,2)</code> Require as dd/mm/yyyy.</p>
  
  <p>In VB to calculate Gender I use --> <code>Gender=IIf(Mid([idno],7,1) Between 0 And 4,"Female","Male")</code>.</p>
  
  <p>I use the following similar input text boxes on my form. How do I adjust it for birthdate and gender respectively please?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;tr&gt;
  &lt;td style="font-weight: bold"&gt;&lt;div align="right"&gt;&lt;label for="name"&gt;birthdate&lt;/label&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="birthdate" type="text" class="input" size="20"  /&gt;&lt;/td&gt;
  &lt;/tr&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  require_once("connect.php");
      //include("connect.php");   
      $msg = "";
      if(isset($_POST["submit"]))
      {   
          $idno = $_POST["idno"];
          $gender = $_POST["gender"];
          $birthdate = $_POST["birthdate"];
          $age = $_POST["age"];
  
  
          //++++
          $idno = mysqli_real_escape_string($mysqli, $idno);
          $gender = mysqli_real_escape_string($mysqli, $gender);
          $birthdate = mysqli_real_escape_string($mysqli, $birthdate);
          $age = mysqli_real_escape_string($mysqli, $age);
  
  
  
  
  
          {
              //$msg = "Sorry...This email already exist...";
          }
          //else
          {
  
              $query = mysqli_query($mysqli, "INSERT INTO tblpersons (gender,idno,birthdate,age)VALUES ('$gender','$idno','$birthdate','$age')");
  
              if($query)
              {
                  $msg = "Thank You! you are now registered.";
              }
          }
      }
  ?&gt;
  
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  
  
  
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
   &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  &lt;style&gt;
  &lt;title&gt;Race Registration Form by Zululand Multisport&lt;/title&gt;
  
  label
  {
      font-family:Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
      font-size:20px;
      font-weight:bold;
  }
  .input
  {
      padding:5px;
      font-family:Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
      font-size:18px;
  }
  input[type=submit]
  {
      padding:5px;
      font-family:Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
      font-size:18px;
      font-weight:bold;
      background:#999;
      border:2px solid black;
      color:#FFF;
  }
  fieldset
  {
      width: 500px;
  }
  fieldset legend
  {
      padding:2px;
      font-family:Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
      font-size:14px;
      font-weight:bold;
      background:#999;
      border:2px solid black;
      color:#FFF;
  }
  .error
  {
      color:red;
      font-family:Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", monospace;
      font-size:16px;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  function limitText(limitField, limitNum) {
      if (limitField.value.length &gt; limitNum) {
          limitField.value = limitField.value.substring(0, limitNum);
      }
  
  &lt;/script&gt;
  
  &lt;body&gt;
  
  &lt;form method="post" action=""&gt;
  
  &lt;/tr&gt;
  &lt;td height="23"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;div align="left"&gt;
  &lt;input type="submit" name="submit" value="Home" /&gt;
  &lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;fieldset&gt;
  
  
  &lt;legend&gt;Registration Form for Personal Details  -  (&amp;copy; Neels Ferreira - 2017) &lt;/legend&gt;
  &lt;?php echo $todaydate = date('d/m/Y');?&gt;
  
  
  &lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'&gt;&lt;/script&gt;
     &lt;link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"&gt;
    &lt;link rel="stylesheet" href="/resources/demos/style.css"&gt;
    &lt;script src="https://code.jquery.com/jquery-1.12.4.js"&gt;&lt;/script&gt;
    &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
  
  &lt;table width="600" border="2" cellpadding="10" cellspacing="10"&gt;
  
  &lt;tr&gt;
  &lt;td colspan="1" align="center" class="error"&gt;&lt;?php echo $msg;?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  
  &lt;tr&gt;
  &lt;td style="font-weight: bold"&gt;&lt;div align="right"&gt;&lt;label for="name"&gt;idno&lt;/label&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="idno" type="text" class="input" size="20" onKeyDown="limitText(this,13);" 
  onKeyUp="limitText(this,13);"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td style="font-weight: bold"&gt;&lt;div align="right"&gt;&lt;label for="name"&gt;birthdate&lt;/label&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="birthdate" type="date" class="input" size="20"  /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td style="font-weight: bold"&gt;&lt;div align="right"&gt;&lt;label for="name"&gt;gender&lt;/label&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="gender" type="date" class="input" size="10"  /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td style="font-weight: bold"&gt;&lt;div align="right"&gt;&lt;label for="name"&gt;age (31/12)&lt;/label&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="age" type="text" class="input" size="10" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  
  &lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'&gt;&lt;/script&gt;
  
  &lt;td height="23"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;div align="left"&gt;
  &lt;input type="submit" name="submit" value="Add Personal Details and Continue!" /&gt;
  &lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  
  
  
  
  <pre class="lang-html prettyprint-override"><code>CREATE TABLE `tblpersons` (
    `entriesid` int(11) NOT NULL,
    `Idno` varchar(20) NOT NULL,
    `gender` varchar(10) NOT NULL,
    `age` varchar(10) NOT NULL,
    `birthdate` date NOT NULL,
    `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
  --
  -- Dumping data for table `tblpersons`
  --
  
  INSERT INTO `tblpersons` (`entriesid`, `Idno`, `gender`, `age`, `birthdate`, `timestamp`) VALUES
  (121,  '6302185142311', 'male',  '32', '1963-02-18','2016-11-26 22:10:53');
  </code></pre>
  
  <p>Please assist with PHP and where I add it to this HTML code. </p>