ORA error

greenspun.com : LUSENET : WebdesignII : One Thread

I finally have a check set up, so that I can check a resturant name that has been entered against those already in the database and send the user on to the rating form if the name already exists.

The problem is with the select statement i'm using: it fails if there is no match for the resturant name. here's the SELECT:

set db [ns_db gethandle]

#OK if there's a rest_name match, but ORA error if not set check [database_to_tcl_string $db "select rest_name from rest where lower(rest_name)=lower('$rest_name')"]

if { [string compare -nocase $rest_name $check] == 0} { set rest_id [database_to_tcl_string $db "select rest_id from rest where lower(rest_name)=lower('$check')"] ns_returnredirect "rest_rate_form.tcl?rest_name=$rest_name&rest_id=$rest_id" exit }

What I need the script to do here is continue to the next part of the script if no matching resturant name is found. Here's the second part:

set val [database_to_tcl_string $db "select rest_id.nextval from dual"] ns_db dml $db "insert into rest(rest_id,rest_name) VALUES($val,'$rest_name')"

ns_returnredirect "rest_rate_form.tcl?rest_name=$rest_name&rest_id=$val"

The question is how to proceed? Any hints?

-- Tony (antl@it-c.dk), April 21, 2002


the problem WAS the first select.

should have used the "0or1row" function instead of "database_to_tcl_string"

-- Tony (antl@it-c.dk), April 21, 2002.

Moderation questions? read the FAQ