Readers, Please could someone help to explain why the following code fails: <?php $uploaddir = '~/tmp/cpac/cpactmp/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $dbconnect = pg_connect("dbname=cpacweb user=cpaca"); $targetfilepath = $uploaddir . $uploadfile; if(isset($_POST["submit"])){ $csvfile=$_FILES["userfile"]["tmp_name"]; if($_FILES["userfile"]["tmp_name"] > 0) { $csvfileopen=fopen($csvfile, "r"); while(($csvfiledata=fgetcsv($csvfileopen, 10000, ","))){ $csvinsert = "INSERT into somedata(name, id, emailaddress, groupname) VALUES ('".$csvfiledata[0]."', '".$csvfiledata[1]."', '".$csvfiledata[2]."', '".$csvfiledata[3]."')"; } } fclose($csvfileopen); } $query = "SELECT * FROM somedata"; $result = pg_exec($dbconnect, $query); echo "Number of rows: " . pg_numrows($result); pg_freeresult($result); pg_close($dbconnect); ?> The trial csv file contains 2 rows of data, but the query result is zero.