title: Populate php dropdown box from postgresql database
body: <p>I need to populate a dropdown list of book titles from my postgreSQL database using a query such as SELECT title FROM books WHERE ownedBy = [users facebook ID] and then use the selection by the user to display the rest of the information on that book. The page is a facebook app, which is how I'm getting the facebook ID.</p>
  
  <p>This is the relavent section of code so far, mostly created from various answers to similar questions I have found.</p>
  
  <pre><code>&lt;form action="updateform.php" method="post"&gt;
  &lt;select name="booktitle" id="booktitle"&gt;
  &lt;option&gt;Select book&lt;/option&gt;
  &lt;?php
  $db = pg_connect("host=ec2-54-243-190-226.compute-1.amazonaws.com port=5432 dbname=d6fh4g6l0l6gvb    user=zmqygfamcyvhsb password=1Apld4ivMXSK8JZ_8yL7FwIuuz sslmode=require options='--client_encoding=UTF8'") or   die('Could not connect: ' . pg_last_error());
  $sql = pg_query("SELECT title FROM books WHERE ownedby='$user_id'";
  while ($row = pg_fetch_assoc($sql)) {
  echo '&lt;option value="'.htmlspecialchars($row['title']).'"&gt;&lt;/option&gt;';}
  pg_close($db);
  ?&gt;
  &lt;/select&gt;
  &lt;input type="hidden" name="userid" id="userid" value="&lt;?php echo htmlspecialchars($user_id); ?&gt;"&gt;
  //other form elements here
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>UPDATED: I hadn't closed the hidden field, so that seemed to fix the error where it wasn't showing up. The dropdown list is not populating, but I am not getting any errors in the server log.</strong></p>
  
  <p>If anyone can help me get the drop down box part to work, that would be great for now, I'll work on figuring the rest out myself once this part is working.</p>