Page 1 of 1

What is wrong with this code ??

Posted: Fri Sep 26, 2003 10:26 am
by nirma78
I am trying to insert an uploaded file into oracle database - blob field from a PHP script.

Below is my code, could you please tell where I am doing something wrong. It doest give me any error while running it, but it doesnt save data into the table either.

PLEASE HELP !!
Thanks in advance

Code: Select all

<?php

include_once("header.inc.php");
include_once("config.php");
include_once("adodb/adodb.inc.php");

$person_id = $_POST['PID'];
$filename = $_FILES['userfile']['name'];

$uploaddir = "check/". $_FILES['userfile']['name'];
echo " The older file location is : $uploaddir";

$file_dest = str_replace("","/",$uploaddir);
echo " The new file location is $file_dest";

$up = move_uploaded_file($_FILES['userfile']['tmp_name'], $file_dest);
chmod($uploaddir,0644);
chmod($file_dest,0644);
//var_dump($up);

if($up)
{
// echo "File uploaded";
 $query1 = "SELECT application_id
                  FROM application_info
                  WHERE person_id = $person_id";
 $app_result = $db->Execute($query1);
 $app_id = $app_result->fields[0];
 ?>
 <p><?php echo "Application ID found is : $app_id"; ?> </p>
 <?php
 $query2 = "SELECT application_material_id
            FROM application_material
            WHERE material_type like 'Transcript'";
 $mat_result = $db->Execute($query2);
 $app_mat_id = $mat_result->fields[0];
 ?>
 <p><?php echo "Application Material ID found is : $app_mat_id"; ?> </p>
 <?php
 $main_query = "INSERT INTO submitted_material_list
                       (Application_Material_ID,
                        Application_ID,
                        Physical_Copy,
                        Rec_By,
                        Rec_Date)
                VALUES (1,
                        $app_id,
                        LOAD_FILE("$file_dest"),
                        $app_id,
                        SYSDATE)";
 $result = $db->Execute($main_query);
 
 $query3 = "SELECT physical_copy
            FROM submitted_material_list
            WHERE application_material_id = 1
            AND application_id = $app_id
            AND Rec_Date=SYSDATE";

 $found = $db->Execute($query3);
 if($found)
   {
      echo "DATA SAVED !!";
   }
 else
   {
      echo " NOT SAVED !!";
   }
}
else
{
  echo "Not uploaded";
}
?>

Posted: Fri Sep 26, 2003 12:43 pm
by Leviathan
Can you give us a printout of all your echo statements please?

Posted: Fri Sep 26, 2003 1:05 pm
by nirma78
Thanks for replying, I had been waiting for some reply since morning !!

The printout of echo statements in order of occurence is below :

The older file location is : check/GBCB_6.pdf
The new file location is check/GBCB_6.pdf
Application ID found is : 63

Application Material ID found is : 1

DATA SAVED !!


I tried to track on whether the query with the load_file() is getting executed ... and found out that its not...

Is there anything wrong with the way I have written it ?? How can I solve this problem ??

Please help ...
Thanks once again
Nirali

Posted: Fri Sep 26, 2003 1:13 pm
by nirma78
hey just an update on what I had been trying out !!

Code: Select all

<?php
$main_query = "INSERT INTO submitted_material_list
                       (Application_Material_ID,
                        Application_ID,
                        Physical_Copy,
                        Rec_By,
                        Rec_Date)
                VALUES (1,
                        $app_id,
                        LOAD_FILE("$file_dest"),
                        $app_id,
                        SYSDATE)";
 $result = $db->Execute($main_query) or die($db->ErrorMsg());
?>
the error msg is : ORA-00904: "LOAD_FILE": invalid identifier

What should I do to solve this error ??

Can anyone please help me !!

Thanks in advance

Posted: Fri Sep 26, 2003 3:18 pm
by JAM
With some exceptions, inside " (double quotes) you should use ' (single quotes) and vice verca.

Code: Select all

// two examples
$var = "select * from foo where id = '$id'";
$var = "insert into foo (bar) values ('something')";
// and yours
$main_query = "INSERT INTO submitted_material_list
                       (Application_Material_ID,
                        Application_ID,
                        Physical_Copy,
                        Rec_By,
                        Rec_Date)
                VALUES ('1',
                        '$app_id',
                        LOAD_FILE('$file_dest'),
                        '$app_id',
                        'SYSDATE')";
Try and see if something like this might help.