Upload and View a File (image/pdf/doc) in a List of Oracle Apex Page

Uploading and viewing a file (image/pdf/doc) in the Oracle Apex page is sometimes problematic if we miss steps that we should do. But this is very easy and simple thing as I have experienced. I have kept the process in very easy 8 steps, kindly go through them, they are really easy and will take few minutes only!

1. INSERT 5 FIELDS IN DATA FOR FILE UPLOADING:

When we have decided to uplaod a file, we should have few db columns in our table:


FILE_LOB
FILE_NAME
FILE_MIMETYPE
FILE_UPDATEDATE
FILE_CHARACTERSET

here, the file_name is for holding the full image name (with extension) and file_characterset is used for determining whether it is a 32 bit or 64 bit characterset file.
Continue reading

Advertisements

Weka as a Machine Learning Tool

Last day we had a wonderful class where we were introduced us with ‘Weka’. It is generally used as a machine learning tool. Downloaded Weka from sourceforge  and installed it in our computer.

For a demo, we followed following steps:

  1. when the GUI of Weka was on the screen, clicked on Explorer and opened a new screen.
  2. Open File… C:\\Program Files –> Weka –> Data –> iris.arff
  3. now, if we click on ‘EDIT’ button, we can see the sample data
  4. if we click on ‘CLASSIFY‘ tab, we can find ‘ZeroR’ method is selected as Classifier
  5. if we click on ‘START‘, we will find result of the classifier and we can read it
  6. in ‘classifier’ option and click on it, we can see a tree option there. We chose Classifier–>Tree–>J48

searching on web, I found a good tutorial on the same topic in this website. you can to through this!

We learned about Training and Testing. We also learned about Classification and clustering. I found it so interesting.

We learned about  Precision and Recall.  There are True Positive, False Positive, True  Negative and False Negative things to learn. Wikipedia on this topic could help.

# Who are interested to learn more, Andrew Ng from Stanford University could help with the Coursera materials from Machine Learning Section. This is a strong reference.

Push Pop program for 8086 microprocessor

CODE	SEGMENT
	ASSUME CS:CODE,DS:CODE,SS:CODE
	ORG 1000H
	
	MOV AX,0000H
	MOV DS,AX
	MOV SS,AX
	
	MOV AL,100
	MOV BL,00H
	CALL RANDOM
	
	INT 3

RANDOM PROC NEAR
	
	PUSHF
	PUSH CX
	PUSH DX

	MOV CL,AL
	MOV AX,0000H
	MOV AL,17
	MOV DL,SEED
	MUL DL
	ADD AX,0043
	DIV CL
	MOV BL,AH
	MOV SEED,AH

	POP DX
	POP CX
	POPF
	RET

RANDOM ENDP

;              SEED VALUE

	ORG 1500H
	SEED DB 27
	
CODE	ENDS
	END

PHP session lost after redirecting the page

I was inserting some data and was trying to show my success message using SESSION variables in PHP. my code segment of samplepage.php was like this:

if(isset($_POST["Add"]))
{
    $txtName=$_POST['txtName'];
    $txtKey= $_POST["txtKey"];
         
    //when submit button is add
    if($btnValue=="Add")
    {
        if($txtName<>"") //Permission Name can't be blank
        {
            $query = "insert into Table(NAME, KEY) values('$txtName','$txtKey')" ;
            $st = oci_parse($conn, $query);                             
            $success = oci_execute($st,OCI_DEFAULT); // oci as db is oracle here
            oci_commit($conn);
             
            if($success ==1)
            {
            $_SESSION['MySuccessMsg'] = "Data Added Successfully!";
            header('Location: samplepage.php');
            } 
                
               }
         
        }
}

and below this segment I was catching the $_SESSION[‘MySuccessMsg’] in a div in top of my HTML body:

                if(isset($_SESSION['MySuccessMsg'])) // receiving SESSION message .
		{ $msg = $_SESSION['MySuccessMsg'];}				
                echo "<strong>".$msg1."</strong>";  } 
                unset($_SESSION['MySuccessMsg']); //unset session variable
?> 

so every time the page was redirected after $success==1 condition segment, I found no data in $msg.

Later I found a help and realized, it is of 2 cases:

1) make sure session_start() is at the top of the page.
2) use exit() right after where the page is redirected from.

so my new code segment of insert becomes:

     if($success ==1)
     {
	$_SESSION['MySuccessMsg'] = "Data Added Successfully!";
	header('Location: permission.php');
	exit(); // this one is important to keep the session variable hold data even after re-direct	
     }  

NOTE: even if we redirect the page, it still executes the code till the end. therefore my session variable was being unset. so, EXIT() function works here not to unset the variable and code stops execution and moves to the redirected page immediately.

thanks to: stackoverflow

How to avoid duplicate entry in each page reload after PHP submit

I was using form submit using method=’POST’ and action=$_SERVER[‘PHP_SELF’]. I added data in my DB successfully but whenever I manually reloaded my page, it was a duplicate entry. using POST variables carefully, I was unable to resolve the problem.

here goes my code segment of samplepage.php:


if(isset($_POST["Add"]))
{
	$txtName=$_POST['txtName'];
        $txtKey= $_POST["txtKey"];
		
	//when submit button is add
	if($btnValue=="Add")
	{
		if($txtName<>"") //Permission Name can't be blank
		{
		    $query = "insert into Table(NAME, KEY) values('$txtName','$txtKey')" ;
		    $st = oci_parse($conn, $query);								 
	            $success = oci_execute($st,OCI_DEFAULT); // oci as db is oracle here
		    oci_commit($conn);
			
		    if($success ==1)
		    {
		     $SuccessMessage = "Data Added Successfully!";
		    }  
               
               }
        
        }
}

Later, I realized that no matter what how I check the post variables and use them carefully, the variables holds data and in manual reload of the page they were being inserted.

The solution is to RE-DIRECT the page!!.

So, the code segment becomes:

if($success ==1)
		{
		   $SuccessMessage = "Data Added Successfully!";
                   header('Location: samplepage.php');
		} 

Difference between include() and include_once() Functions in PHP

When should I use require vs. include?

The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.

When should I use require_once vs. require

The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again.

thanks to stackoverflow

Creating a trigger for a sequence that works for auto-increment of PK

after creating a sequence like ‘SEQUENCE_NAME_SEQ’ that will increase value from 1 and by 1. then this code will be executed.


CREATE OR REPLACE TRIGGER "DATABASE_NAME"."BI_TRIGGER_NAME" 
  before insert on "TABLE_NAME"               
  for each row  
begin   
    select "SEQUENCE_NAME_SEQ".nextval into :NEW.PRIMARY_KEY_NAME from dual; 
end; 
/
ALTER TRIGGER "DATABASE_NAME"."BI_TRIGGER_NAME" ENABLE;