title: Cannot insert foreign key value
body: <p>I've made two tables to store user information, and the photo information they uploaded.
  Everything goes well, except when I try to insert userID to photos table, mysql just don't take it. The problem might comes from the foreign key things, but I don't know how to fix it.  </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS users (
    userID smallint(7) NOT NULL auto_increment,
    email varchar(60) collate utf8_unicode_ci NOT NULL default '',
    PRIMARY KEY  (userID),
    UNIQUE KEY email (email)
  ) ENGINE=INNODB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  
  
  CREATE TABLE IF NOT EXISTS photos (
   photoID MEDIUMINT(7) NOT NULL AUTO_INCREMENT,
   userID SMALLINT(7),
   title       VARCHAR(150),
   brief    TEXT,
   PRIMARY KEY(photoID),
   INDEX (userID),
   FOREIGN KEY (userID)
   REFERENCES users(userID)
   ) ENGINE=INNODB; 
  </code></pre>
  
  <p>And the sql command I used to insert information to photos table</p>
  
  <pre><code>$sql = "INSERT INTO photos (userID ,title, brief)".
         "VALUES ('$uid', '$title','$bodytext')";
  </code></pre>
  
  <p>Even if the <code>$uid</code> is replaced by a static number like '2', which exists in user table(userID), it's still cannot be inserted.</p>
  
  <p>I took some advices to add <code>mysql_error</code> function, however, it doesn't show anything...</p>
  
  <pre><code>$sql = "INSERT INTO photos (userID ,title, brief)".
         "VALUES ('2', '$title','$bodytext')";
  $res = mysql_query($sql);
  
  if ($res === FALSE) {
    die(mysql_error());
  }
  
  return mysql_query($sql);
  </code></pre>