title: PHP function only working once
body: <p>I'm trying to encrypt three sets of data to insert into MySQL database. However only the first one is working ($email). 
  Firstly I post data from a form, make several checks (does the user exist etc...). At this point I encrypt the email to check with the database (already exists). If the data doesn't already exist, it will encrypt the first names and surnames and insert them into the database. 
  It does encrypt the first name and surname, but not correctly. Only the email encryption works. (Checked by decrypting the data on another script).</p>
  
  <p>Thanks
  Jonathan</p>
  
  <pre><code>&lt;?php
  
  $email = $_POST['emailreg'];
  $firstna = $_POST['firstna'];
  $surna = $_POST['surna'];
  $password = $_POST['passreg'];
  $passconfirm = $_POST['passconfirm'];
  $userpass = $email . $password;
  $emailsep = explode("@", $email);
  $domain = $emailsep[1];
  
  
  $key = md5('united');
  $salt = md5('united');
  
  function encrypt($string, $key) {
      $string = rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB)));
      return $string;
  }
  
  
  
  $link = mysql_connect('xxxxxxx', 'xxxxxxx', 'xxxxxxx');
  
  if (!$link) {
      die('Could not connect: ' . mysql_error());
  }
  
  mysql_select_db("xxxxxxx", $link);
  
  $domaincheck = mysql_query("SELECT * FROM xxxxxxx WHERE domain = '$domain'", $link);
  if($domaincheck === FALSE) { 
      die(mysql_error());
  }
  
  $emailcheck = mysql_query("SELECT * FROM xxxxxxx WHERE studentemail = '".encrypt($email, $key)."'", $link);
  if($emailcheck === FALSE) { 
      die(mysql_error());
  }
  
  $dorow = mysql_fetch_array($domaincheck);
  $emailrow = mysql_fetch_array($emailcheck);
  
  
  if ($password == '') {
  $cause = 'Password Blank'; include 'error.php';
  }elseif ($passconfirm =='') {
  $cause = 'Password Blank'; include 'error.php';
  }elseif ($password != $passconfirm) {
  $cause = 'Password Mismatch'; include 'error.php';
  }elseif ($dorow['domain'] != $domain) {
  $cause = 'Incorrect Domain'; include 'error.php';
  }elseif ($emailrow['studentemail'] != '') {
  $cause = 'User Already Exists'; include 'error.php';
  }elseif ($dorow['licensecount'] &gt; $dorow['licensemax']) {
  $cause = 'Insufficient Licences'; include 'error.php';
  }else {
  
  function hashword($string, $salt){
      $string = crypt($string, '$1$' . $salt . '$');
      return $string;
  }
  
  
  
  
  $userpass = hashword($userpass, $salt);
  
  
  $hash = md5( rand(0,1000) );
  
  
  
  
  $result = mysql_query("INSERT INTO `xxxxxxx`.`xxxxxxx` (`hash`, `studentemail`, `studentfirstname`, `studentsurname`, `oscopetutcount`, `siggentutcount`, `mmetertutcount`, `lprobetutcount`, `psupplytutcount`, `oscopetest`, `siggentest`, `mmetertest`, `lprobetest`, `psupplytest`, `exam`, `userpass`, `ID`, `domain`, `licensecount`, `licensemax`, `licenceexpire`) VALUES ('$hash', '".encrypt($email, $key)."', '".encrypt($firstna, $key)."', '".encrypt($surna, $key)."', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '$userpass', NULL, '', '0', '', NULL)", $link);
  
  $licenceadd = mysql_query("UPDATE xxxxxxx.xxxxxxx SET licensecount = licensecount +1 WHERE domain = '$domain'", $link);
  
  if($result === FALSE) { 
      die(mysql_error()); 
  }
  
  if($licenceadd === FALSE) { 
      die(mysql_error()); 
  }
  
  include 'email.php'; 
  
  
  
  
  mysql_close($link); 
  }
  
  ?&gt;
  </code></pre>