Page 1 of 1

Bulk uploading to Oracle using PHP..

Posted: Sun Jun 27, 2004 5:35 pm
by FreeBaGeL
Hi, I'm in a class at UF where I have to build a website using PHP and Oracle...neither of which are taught in the class. So, I've had to start from scratch and learn on my own. One of the functions necessary for the site is to be able to bulk upload some data in the form of a .csv file into the oracle database.

I've written a script for it, but I can't get it to work. Since my knowledge of PHP is limited, and PHP doesn't have a compiler or any error checking, I don't know what the problem is. Here's the script, any help or pointing in the right direction would be VERY much appreciated:

Code: Select all

#!/usr/local/bin/php
<?

//check if cookie is still valid
$AdminCookie = $HTTP_COOKIE_VARS["Admin"];
if ($AdminCookie=="PWGood"){
  setcookie("Admin", "PWGood", time() + 600);
 }


  //$connection = ocilogon('username', 'password', 'orcl');

  //gets the file//
  $files = $_FILES['userfile']['tmp_name'];


if (file_exists($file_name))
{
  $lines = file($files);
}

  else
  {
    echo "Cannot find file";
  }

  foreach ($lines as $line_num => $line) 
  {
   //first we'll get the professor's id//
   $student_idlocal=strpos($line,"|");
   $student_id=substr($line,0,$student_idlocal);

   //first name//
   $last_namelocal=strpos($line,"|",$student_idlocal+1);
   $last_name=substr($line,$student_idlocal+1,($last_namelocal-$student_idlocal)-1);
 
   //last name//
   $first_namelocal=strpos($line,"|",$last_namelocal+1);
   $first_name=substr($line,$last_namelocal+1,($first_namelocal-$last_namelocal)-1);

   //Query to insert each professor into db//
   $query1 = "INSERT INTO ROSTER VALUES ('$student_id','$last_name','$first_name')";
   
   parse n' execute//
   $results = OCIParse($connection,$query1);
   $doquery1 = OCIExecute($results);

   /tml confirmation of upload//
   echo "<p>$last_name, $first_name</p>";


$url = "http://www.cise.ufl.edu/~rmoyer"; // target of the redirect
$delay = "3"; // 3 second delay

echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

  }

?>

Posted: Sun Jun 27, 2004 5:43 pm
by FreeBaGeL
Btw, here is a link to the file it must be able to upload:

http://www.cise.ufl.edu/class/cen3031su ... roster.csv

Posted: Sun Jun 27, 2004 5:46 pm
by feyd

Code: Select all

parse n' execute//                                                        <-- this line
   $results = OCIParse($connection,$query1); 
   $doquery1 = OCIExecute($results); 

   /tml confirmation of upload//                                             <-- and this line
   echo "<p>$last_name, $first_name</p>";
are the highlighted lines apart of your actual script? if so, those will cause parse errors. move the // to the front of the line.

Posted: Sun Jun 27, 2004 5:59 pm
by FreeBaGeL
feyd wrote:

Code: Select all

parse n' execute//                                                        <-- this line
   $results = OCIParse($connection,$query1); 
   $doquery1 = OCIExecute($results); 

   /tml confirmation of upload//                                             <-- and this line
   echo "<p>$last_name, $first_name</p>";
are the highlighted lines apart of your actual script? if so, those will cause parse errors. move the // to the front of the line.
They're actually commented out in the actual script, that must've just happened when I was pasting it over. They look like:

//parse n' execute//
$results = OCIParse($connection,$query1);
$doquery1 = OCIExecute($results);

//html confirmation of upload//
echo "<p>$last_name, $first_name</p>"

Posted: Sun Jun 27, 2004 7:09 pm
by redmonkey

Code: Select all

if (file_exists($file_name))
Where is the $file_name variable set?

It seems you are attempting to get various bits of info by looking for the '|' delimiter with the file being uploaded, yet the sample file you have given does not conatin any pipe delimited data.

You could also try setting PHPs error reporting (error_reporting()) to 'E_ALL' (if it's not alreadt) which may help track down some problems.

Posted: Sun Jun 27, 2004 8:25 pm
by FreeBaGeL
Well, it would appear as if I'm now getting an "Internal Server Error" which likely means something else is the problem.

Also, how do I put that error reporting in?

Just stick error_reporting(E_ALL); in my code?

Thanks.

Posted: Sun Jun 27, 2004 8:30 pm
by feyd
I tend to do the following for making sure error reporting and errors (generally) display:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors','1');
the only problem with doing it in code, is if there's a parse error, it may not show.. :roll:

Posted: Sun Jun 27, 2004 8:36 pm
by FreeBaGeL
Hmmm, not seeing any new errors after I added that. Here's what shows up on the page when I try and run the script:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@cise.ufl.edu and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Posted: Sun Jun 27, 2004 8:55 pm
by redmonkey
A couple of things to look at....

Does your server require the hashbang line? and if so, is it set to the correct path?
Does the script have the appropriate file permissions set to allow your webserver to execute it?

These are two of the most common reasons (that I come across anyway) for 'Internal Server Errors' when dealing with CGI scripts.