title: Creating a mechanism to validate emails
body: <p>I already have an advanced user login/register system on my website (<a href="http://colemansystems.psm2.co.uk" rel="nofollow noreferrer">colemansystems.psm2.co.uk</a>). However, I would like to have a email sent to new users for verification of their email address. If they have not clicked the link they will not be able to access their account. I am semi-experienced with PHP and MySQL, so please explain in depth.</p>
  <p>The code I'm using for the <code>verify.php</code> file (the link the user click on with a GET (for example, <code>verify.php?d=51773199320</code>))</p>
  <pre><code>$secret = $_GET['d'];
  $result = mysql_query(&quot;SELECT valid FROM users WHERE secret=$secret&quot;);
  while ($row = mysql_fetch_array($result))
  {
      $valid = $row['valid'];
  }
  if ($valid == &quot;&quot;) {
      echo&quot;There seems to be a problem with the verification code.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&quot;;
  }
  elseif ($valid == &quot;1&quot;)
  {
      echo&quot;Your account is already verified.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&quot;;
  }
  else
  {
      mysql_query(&quot;UPDATE users SET valid = '1' WHERE secret=$secret&quot;);  
      echo &quot;Thank you, your account is now verified and you are free to use the exclusive features!&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&quot;;
  }
  </code></pre>
  <p>Is this secure?</p>