title: import CSV file into postgres via php in web page
body: <p>Hi I'm trying to build a web interface that will allow people to import the contents of a csv file into a postgresql database. Below is the php component of what I'm trying to do, however when I run I just get "There was a problem uploading your data:" from my die command but with no other error. </p>
  
  <p>For this example, I have hardcoded a value for the csv file, however the intent is for the user to point at a csv file on their machine or network location.</p>
  
  <pre><code>&lt;?php
  
  if ($_POST['submit']) {
  // attempt a connection
  $dbh = pg_connect("host=localhost dbname=blah user=user password=pass123");
  if (!$dbh) {
  die("Error in connection: " . pg_last_error());
  }
  // execute query
  $sql = "COPY personaldetails(name, email, postaladdress, phone, username, password) FROM '../Test/Book1.csv' WITH DELIMITER ',' CSV";
  
  $result = pg_query($dbh, $sql);
  if (!$result) {
  die("There was a problem uploading you data: " . pg_last_error());
  }
  
  echo "Data successfully inserted!";
  
  // free memory
  pg_free_result($result);
  
  // close connection
  pg_close($dbh);
  }   
  
  ?&gt;
  </code></pre>
  
  <p>I appreciate any help that can be offered.</p>