Add a Car to the Database

Oracle Connection unsuccessful. Please try again later."; $err = OCIError(); echo "
Error: ".$err[text]; echo ""; exit(-1); } $carname=trim($_POST['carname']); if (!isset($_POST['carname'])){ //Display Form ?>
Car Name:
Image File:
'; $n99problems=false; //check if all form fields were filled if ($carname==''){ print '
  • Name field is empty
  • '; $n99problems=true; } else { print '
  • Name field = ' . $carname . '
  • '; } print ''; // // make a blob from the uploaded file // // get the name of the file on the web server $tmpname = $_FILES['userimage']['tmp_name']; // create a lob object $lob = oci_new_descriptor($conn, OCI_DTYPE_LOB); // prepare a statement to do the insertion $stmt = oci_parse($conn, "insert into cars (name, image) values(:carname, :image) returning image into :image"); // bind variables to the statement oci_bind_by_name($stmt, ':carname', $carname); oci_bind_by_name($stmt, ':image', $lob, -1, OCI_B_BLOB); // this is absolutely necessary $lob->writeTemporary(" ",OCI_TEMP_BLOB); // execute the statement $r = oci_execute($stmt, OCI_NO_AUTO_COMMIT); if (!$r) { // if false there was an error $e = oci_error($stmt); echo htmlentities($e['message']); } // fill in the blob with data from the file if ($lob->savefile($tmpname)){ oci_commit($conn); echo "Image successfully uploaded\n"; }else{ echo "Couldn't upload Image\n"; } // we're done! oci_free_descriptor($lob); oci_free_statement($stmt); oci_close($conn); } oci_close($conn); ?>