Don't write the code as separate statements. Use elseif
(you can read the documentation here):
if (not exists(select id from transactions where tel = last_inserted_number)) then
insert into transactions(message, tel)
values(last_inserted_message, last_inserted_number);
insert into outbox(out_message, out_number)
values("go to step 1", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_1='')) then
update transactions set step_1=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 2", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_2='')) then
update transactions set step_2=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 3", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_3='')) then
update transactions set step_3=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 4", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_4='')) then
update transactions set step_4=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 5", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_5='')) then
update transactions set step_5=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 6", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_6='')) then
update transactions set step_6=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 7", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_7='')) then
update transactions set step_7=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 8", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_8='')) then
update transactions set step_8=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("go to step 9", last_inserted_number);
elseif ( exists(select id from transactions where tel = last_inserted_number && step_9='')) then
update transactions set step_9=last_inserted_message where
tel=last_inserted_number;
insert into outbox(out_message, out_number)
values("success.you have completed the form", last_inserted_number);
end if;
I'm not 100% sure this is the logic that you want. If not, it should guide you on what to do.