title: Erratic Problems Adding User ID to MySQL Table of User Lists
body: <p>I have a site where users can log-in and add items to a list.</p>
  
  <p>The user logs in and the session stores their e-mail, which I use to identify them in a user table.</p>
  
  <p>Then, they can input a list item and add to a list table that contains their ID and their list items.</p>
  
  <p>Sometimes the ID is added and sometimes it comes up null (however, the list item text is always added).  This seems erratic because most of the time the ID is included.</p>
  
  <p>Any ideas?  The table type is MyISAM.  I'm new to programming, btw.</p>
  
  <p>Here's an example of my code:</p>
  
  <pre><code>&lt;?php 
  session_start();
  $item = $_REQUEST['item'];
  $email = $_SESSION['email'];
  
  if ($item)
  {
  
  mysql_connect("localhost","root","") or die("We couldn't connect!");
  
  mysql_select_db("table");
  
  $query = mysql_query("SELECT ID FROM users WHERE email='".$_SESSION['email']."'");
  $result = mysql_result($query,0);
  $user_id = $result;
  
  mysql_query("INSERT INTO items (user_ID,item_name) VALUES('$user_id','$item')");
  </code></pre>
  
  <p>So every time I test it by logging into my site myself, no problems.  But increasingly, I have users who try to add items and it creates a record where item_name shows up correctly but user_ID is set to 0 (default).</p>