-- make_new_student is invoked by new_student to create the record.
-- Note option for CANCEL
-- also note the exception handler, and try commenting it out and trying
-- to insert a bad record.

create or replace procedure make_new_student
(
	 studid in varchar2,
	 lname  in varchar2,
	 fname  in varchar2,
	 startterm in varchar2,
	 advisor in varchar2,
	 major   in varchar2,
	 theButton in varchar2
) 
as
i number;

begin

    if lower(theButton) = 'cancel'
    then
    	form2;
        return;
    end if;
    
    insert into student values
    (studid, lname, fname, null, null, null, null, startterm, null, advisor, major, null);
    
    --commit;
    
    htp.htmlOpen;
    htp.headOpen;
    htp.title('New Student');
    htp.headClose;
    htp.bodyOpen;

    htp.header(2, 'Student record created (maybe)');
    
    htp.formOpen('/indo/new_student2', 'GET');
    
    htp.formSubmit(NULL, 'ok');

    htp.formClose;
        


    htp.bodyClose;
    htp.htmlClose;

exception
    when DUP_VAL_ON_INDEX then
    	htp.htmlOpen;
    	htp.bodyOpen;
    	htp.header(1, 'insert failed! duplicate key!');
    	htp.print('Student ID = ' || studid);
    	htp.bodyClose;
    	htp.htmlClose;
    when others then
    	htp.htmlOpen;
    	htp.bodyOpen;
    	htp.header(1, 'insert failed! unknown cause!');
    	htp.print('Student ID = ' || studid);
    	htp.bodyClose;
    	htp.htmlClose;
    
   
end;
/
show errors

