title: PDO creating a table with a foreign key
body: <p>I am having difficulty creating a table with MySQL (PDO) with a foreign key element, without the foreign key the table creates fine, but without I get this message: </p>
  
  <p>SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;</p>
  
  <p>I have tried searching for a solution and adapting the code, but seem to keep coming across this. Is there a fix or am I being a wally? </p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = NULL;
  $dbname = "testapplciants";
  
  try {
      $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
      // set the PDO error mode to exception
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  
      //sql to create the activity registered table
      $sql = "CREATE TABLE Activity_Register (
      Activity_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
      participant_id INT(6) FOREIGN KEY (participant_id) REFERENCES participants,
      entry_number INT(2),
      recorded_result INT(6),
      entry_date TIMESTAMP
  
      )";
  
      // use exec() because no results are returned
      $conn-&gt;exec($sql);
      echo "Table Activity Recorder created successfully";
      }
  catch(PDOException $e)
      {
      echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
      }
  
  $conn = null;
  ?&gt; 
  </code></pre>