# Fail/0 in localhost

**URL:** <https://swi-prolog.discourse.group/t/fail-0-in-localhost/843>\
**Category:** Help!\
**Tags:** http\
**Created:** [June 20, 2019, 4:47am UTC](https://swi-prolog.discourse.group/t/fail-0-in-localhost/843 "2019-06-20T04:47:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HM\_MM](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@HM\_MM](https://swi-prolog.discourse.group/u/HM_MM)\
**Post date:** [June 20, 2019, 4:47am UTC](https://swi-prolog.discourse.group/t/fail-0-in-localhost/843/1 "2019-06-20T04:47:27Z")

</div>

I’m having problem with `fail/0` when its run over localhost.

this is my code

- to get user input

```prolog
:- use_module(library(http/thread_httpd)).

:- use_module(library(http/http_dispatch)).

:- use_module(library(http/http_error)).

:- use_module(library(http/html_write)).

:- use_module(library(http/http_parameters)).

:- use_module(eTimber).

:- http_handler(root(data_entry), web_form, []).

server(Port) :-

        http_server(http_dispatch, [port(Port)]).

web_form(_Request) :-

	reply_html_page(

            [title('e-Timber')],

	    [

	     form([action='/landing', method='POST'], [

		p([], [

		  label([for=name],'Concession:'),

		  input([name=concession, type=textarea])

		      ]),

                p([], [

		  label([for=name],'Please select: '),

		  input([name=inventory, type=radio, value="view"]),view_inventory,

                  input([name=inventory, type=radio, value="new"]),new_inventory

		      ]),

                p([], [

		  label([for=name],'Year:'),

		  input([name=year, type=textarea])

		      ]),

                p([], [

		  label([for=name],'Month:'),

		  input([name=month, type=textarea])

		      ]),

                p([], [

		  label([for=name],'Cluster:'),

		  input([name=cluster, type=textarea])

		      ]),

		p([], input([name=submit, type=submit, value='Submit'], []))

	      ])]).

:- http_handler(root(landing), user_input, []).

user_input(Request):-

        http_parameters(Request,
                        [concession(Concession, []),
                          inventory(Inventory, []),
                          year(Year, []),
                          month(Month, []),
                          cluster(Cluster, [])
                        ]),

        format('Content-type: text/html~n~n', []),

        format('<table border=1>', []),
        format('<tr>', []),

        format('<td>', []),
        write("Concession"),nl,
        format('</td>', []),

        format('<td>', []),
        format('<b>', []),
        write(Concession),nl,
        format('</b>', []),
        format('</td>', []),

        format('</tr>', []),

        format('<tr>', []),

        format('<td>', []),
        write("Inventory"),nl,
        format('</td>', []),

        format('<td>', []),
        format('<b>', []),
        write(Inventory),nl,
        format('</b>', []),
        format('</td>', []),

        format('</tr>', []),

        format('<tr>', []),

        format('<td>', []),
        write("Year"),nl,
        format('</td>', []),

        format('<td>', []),
        format('<b>', []),
        write(Year),nl,
        format('</b>', []),
        format('</td>', []),

        format('</tr>', []),

        format('<tr>', []),

        format('<td>', []),
        write("Month"),nl,
        format('</td>', []),

        format('<td>', []),
        format('<b>', []),
        write(Month),nl,
        format('</b>', []),
        format('</td>', []),

        format('</tr>', []),

        format('<tr>', []),

        format('<td>', []),
        write("Cluster"),nl,
        format('</td>', []),

        format('<td>', []),
        format('<b>', []),
        write(Cluster),nl,
        format('</b>', []),
        format('</td>', []),

        format('</tr>', []),

	format('</table>', []),

        check_db(Concession).

```

- at the end of this code - this `check_db(Concession)` which will check whether the database exist or not

- next - this following code

```prolog
%etimber.pl
:- module(etimber,
 [ check_db/1,
    trigger/1,
    ks_agenda/2,
    trigger_list/1
 ]).

:- use_module(db_conn).

%knowledge source

%new concession - db not exist - to create new database
%user upload file(s)
ks_name('create_db',1,'upload_files').
ks_name('create_db',2,'check_files').
ks_name('create_db',3,'correct_files').
ks_name('create_db',4,'incorrect_files').
ks_name('create_db',5,'upload_new_files').
%create table(s) and insert data to table(s)
ks_name('create_db',6,'create_tables').
ks_name('create_db',7,'insertdata_tables').
ks_name('create_db',8,'display_new_tables').

%exisiting concession - db exist
ks_name('display_db',1,'display_tables').
ks_name('display_db',2,'select_table').
ks_name('display_db',3,'tableto_process').

/*TRIGGER LIST @ AGENDA */
ks_agenda(_,[]).

is_member(X, [X|_]). /*X is member of head*/

is_member(X, [_|Y]):- /*X is member of tail*/
    is_member(X,Y).

/*check whether item X exist in ks_tlist*/

exist(X):-
    ks_agenda(_,Control),
    is_member(X,Control).

trigger_list(X):-
    ks_name(X,Y,Z),
    not(exist(Z)),
    assert(ks_agenda('display_db',[Y,Z])),
    fail.

check_db(Concession):-
    open_db,
    db_exist(Concession,Count).

trigger(Q):-
        odbc_fetch(Q, Row, []),
        ( Row == end_of_file
        -> true
        ;
            Row =..[row |Database],
            Database = [DBName],
            (
              DBName =:= 1
              ->
                 writeln('DB exist'),nl,
                 trigger_list('display_db')
                               ;
              DBName =:= 0
              ->
                 writeln('DB NOT exist'),nl,
                 trigger_list('create_db')
            )

       ).

```

the problem is here … `fail` is not working in localhost.  
however - when I tried in SWI-Prolog window - no problem

```prolog

trigger_list(X):-
    ks_name(X,Y,Z),
    not(exist(Z)),
    assert(ks_agenda('display_db',[Y,Z])),
    fail.

```

Thank you.  
-Hana-

---

<div class="post-metadata">

**Author:** ![anniepoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/anniepoo/32/12_2.png) [@anniepoo](https://swi-prolog.discourse.group/u/anniepoo)\
**Post date:** [June 23, 2019, 12:36pm UTC](https://swi-prolog.discourse.group/t/fail-0-in-localhost/843/2 "2019-06-23T12:36:16Z")

</div>

Made this topic public on June 23, 2019, 12:36pm UTC


