Re: postgresql csv import

[email protected] (ourdiaspora)
Newsgroups php.general
Message-ID <KQgACjPrEcBqCbrwBf8yNeetBgXwMeYFGnSuOyLsDXe7XXyCzOUwWZ3dGFL7qOB8NGLe5l-hbTXHNsbut39KHCsC9plqnd_WjqXofOqz01Y=@protonmail.com>
On Monday, September 20th, 2021 at 11:19 PM, Ashley Sheridan <[email protected]> wrote:

> On 20 September 2021 22:49:25 BST, ourdiaspora [email protected] wrote:
> $targetfilepath = $uploaddir . $uploadfile;
	if(isset($_POST["submit"])){
		$filename=$_FILES["userfile"]["tmp_name"];
		if($_FILES["file"]["size"] > 0){
			$file = fopen($filename, "r");
			while (($getdata = fgetcsv($file, 10000, ",")) !== FALSE){
				$dbdataentry = "INSERT INTO somedata(name, id, emailaddress, groupname) VALUES ('".$getdata[0]."','".$getdata[1]."','".$getdata[2]."','".$getdata[3]."')";
				$result = pg_query($dbconnect, $dbdataentry);
				}
			}
			fclose($file);
		 }
> > > So what exactly is your code doing? Check each part:
> >
> Did you attempt to use any kind of simple print statement debugging to see if any of your assumptions are correct?

Changed the file to:

"
...
$targetfilepath = $uploaddir . $uploadfile;
$filename=$_FILES["userfile"]["tmp_name"];
	if(isset($_POST["submit"])){
		$filename=$_FILES["userfile"]["tmp_name"];
		if($_FILES["file"]["size"] > 0){
			$file = fopen($filename, "r");
			while (($getdata = fgetcsv($file, 10000, ",")) !== FALSE){
				$dbdataentry = "INSERT INTO somedata(name, id, emailaddress, groupname) VALUES ('".$getdata[0]."','".$getdata[1]."','".$getdata[2]."','".$getdata[3]."')";
				$result = pg_query($dbconnect, $dbdataentry);
				}
			}
			fclose($file);
		 }
		 print "filename is $targetfilepath";
...
"

The file path was correctly printed in the web browser.

Then substituted the last line above to:

"
...
print "filename is $filename";
...
"

The filename was _not_ printed in the web browser.

Then substituted for:

"
...
print "filename is $_FILES";
...
"

Result printed in web browser:

"
...
Notice: Array to string conversion in
...filename is Array
...
"

Then substituted for:

"
...
print "filename is $file";
...
"

Result printed in web browser:

"
...
Notice: Undefined variable: file in
...
"

Then substituted for:

"
...
print "filename is $getdata";
...
"

Result printed in web browser:

"
...
Notice: Undefined variable: getdata in
...
"

So it would seem that these variables are not being accepted?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.