title: How to define FOREIGN KEY constraint in mysql in my case not working
body: <p>I need to know about how to declare foreign key in mysql and how it works. Here's one sample 
  first table contains <code>name</code>, <code>age</code> the second table refer the first tables <code>name</code>. While I run this, I receive <code>error</code> only.</p>
  
  <pre><code>&lt;?php
  $conn=new mysqli("localhost","root","12345");
  $sql="USE new";
  $conn-&gt;query($sql);
  $sql="CREATE TABLE test(name varchar(20),age integer)";
  $conn-&gt;query($sql);
  $sql="CREATE TABLE test2(name varchar(10),FOREIGN KEY (name) REFERENCES test     (name)";
  if($conn-&gt;query($sql)==true)
  {
      header('Locaton:test3.html');
  }
  else
  {
      echo "error";
  }
  ?&gt; 
  </code></pre>
  
  <p>Can anyone help me?</p>