Salon Appointment Scheduler - syntax error

Hi,
I have code so far:

#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon -c" 

echo -e "\n~~~~~ Your Salon Shop ~~~~~\n"

MAIN_MENU() {
  if [[ $1 ]]
  then
    echo -e "\n$1"
  fi
  echo "How may I help you?"
  echo -e "\n1. Services \n2. Appointment \n3. Exit"
  read SERVICE_OPTION

  case $SERVICE_OPTION in
  1) SERVICE_OPTIONS ;;
  2) APPOINTMENT_CONTROL ;;
  3) EXIT ;;
  *) MAIN_MENU "Please enter a valid option"
  esac
}


SERVICE_OPTIONS () {
# get services
SERVICES_OFFERED=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
echo "$SERVICES_OFFERED" | while read SERVICE_ID BAR NAME
do 
 echo "$SERVICE_ID) $NAME Service"
done

# select service
echo -e "\nWhich service you are looking for?"
read SERVICE_ID_SELECTED

if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
then
  MAIN_MENU "This is not a valid ID"
else
SERVICE_SELECTED=$($PSQL "SELECT service_id, name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
echo "$SERVICE_SELECTED" | while read SERVICE_ID BAR NAME
do
  echo "$SERVICE_ID) $NAME Service"
done

# ask for time
echo -e "\nWhat time is suitable for you?"
read SERVICE_TIME

echo $SERVICE_TIME
# check if time available
SAY_YES=$($PSQL "SELECT available FROM appointments WHERE available = true")

if [[ -z $SAY_YES ]]
then
  MAIN_MENU "Sorry, appointment is not available at this time."
else
# ask for phone
  echo -e "\nWhat is your phone numner?"
  read CUSTOMER_PHONE

# get customer info
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")

if [[ -z $CUSTOMER_NAME ]]
then
  echo -e "\nWhat is your name?"
  read CUSTOMER_NAME

#insert customer into the database
INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi

# get customer_id
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE' ")

#insert appointment
INSERT_APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED)")

SET_TO_FALSE_RESULT=$($PSQL "UPDATE appointments SET available = false WHERE customer_id = $CUSTOMER_ID")

# get appointment info
APPOINTMENT_INFO=$($PSQL "SELECT service_id, time FROM appointments Where time = $SAY_YES")

# display apointment info
MAIN_MENU "I have put you down for the $APPOINTMENT_INFO booked, $($CUSTOMER_NAME | sed -r 's/^ 8| *$//g')."

fi

fi 
}
APPOINTMENT_CONTROL () {
  echo appointment
  MAIN_MENU
}
EXIT () {
  echo thanks
}
MAIN_MENU

and its producing something like:

codeally@34635f801163:~/project$ ./salon2.sh

~~~~~ Your Salon Shop ~~~~~

How may I help you?

1. Services 
2. Appointment 
3. Exit
1
service_id) name Service
------------+-------)  Service
1) cut Service
2) color Service
3) trim Service
4) perm Service
5) style Service
(5)  Service

Which service you are looking for?
3
service_id) name Service
------------+------)  Service
3) trim Service
(1)  Service

What time is suitable for you?
11:00
11:00

What is your phone numner?
555-5555
ERROR:  syntax error at or near "rows"
LINE 3: (0 rows), 3)
           ^
ERROR:  syntax error at or near "rows"
LINE 3: (0 rows)
           ^
ERROR:  syntax error at or near "t"
LINE 3:  t
         ^
./salon2.sh: line 86: name: command not found

I have put you down for the  booked, .
How may I help you?

1. Services 
2. Appointment 
3. Exit

any help to find where the problem is or any improvement in this code?

regards,

Could you share also dump of the database?

here is the salon.sql

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE salon;
--
-- Name: salon; Type: DATABASE; Schema: -; Owner: freecodecamp
--

CREATE DATABASE salon WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';


ALTER DATABASE salon OWNER TO freecodecamp;

\connect salon

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: appointments; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.appointments (
    appointment_id integer NOT NULL,
    customer_id integer,
    service_id integer,
    "time" character varying(50),
    available boolean DEFAULT true
);


ALTER TABLE public.appointments OWNER TO freecodecamp;

--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.appointments_appointment_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.appointments_appointment_id_seq OWNER TO freecodecamp;

--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.appointments_appointment_id_seq OWNED BY public.appointments.appointment_id;


--
-- Name: customers; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.customers (
    customer_id integer NOT NULL,
    phone character varying(50),
    name character varying(50)
);


ALTER TABLE public.customers OWNER TO freecodecamp;

--
-- Name: customers_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.customers_customer_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.customers_customer_id_seq OWNER TO freecodecamp;

--
-- Name: customers_customer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.customers_customer_id_seq OWNED BY public.customers.customer_id;


--
-- Name: services; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.services (
    service_id integer NOT NULL,
    name character varying(50)
);


ALTER TABLE public.services OWNER TO freecodecamp;

--
-- Name: services_service_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.services_service_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.services_service_id_seq OWNER TO freecodecamp;

--
-- Name: services_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;


--
-- Name: appointments appointment_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointments_appointment_id_seq'::regclass);


--
-- Name: customers customer_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.customers ALTER COLUMN customer_id SET DEFAULT nextval('public.customers_customer_id_seq'::regclass);


--
-- Name: services service_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);


--
-- Data for Name: appointments; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.appointments VALUES (1, NULL, NULL, '09:00', true);
INSERT INTO public.appointments VALUES (2, NULL, NULL, '10:00', true);
INSERT INTO public.appointments VALUES (3, NULL, NULL, '11:00', true);
INSERT INTO public.appointments VALUES (4, NULL, NULL, '12:30', true);
INSERT INTO public.appointments VALUES (5, NULL, NULL, '13:30', true);
INSERT INTO public.appointments VALUES (6, NULL, NULL, '14:30', true);
INSERT INTO public.appointments VALUES (7, NULL, NULL, '15:30', true);
INSERT INTO public.appointments VALUES (8, NULL, NULL, '16:30', true);


--
-- Data for Name: customers; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Data for Name: services; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.services VALUES (1, 'cut');
INSERT INTO public.services VALUES (2, 'color');
INSERT INTO public.services VALUES (3, 'trim');
INSERT INTO public.services VALUES (4, 'perm');
INSERT INTO public.services VALUES (5, 'style');


--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.appointments_appointment_id_seq', 1, false);


--
-- Name: customers_customer_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.customers_customer_id_seq', 1, true);


--
-- Name: services_service_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.services_service_id_seq', 1, false);


--
-- Name: appointments appointments_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_pkey PRIMARY KEY (appointment_id);


--
-- Name: customers customers_phone_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.customers
    ADD CONSTRAINT customers_phone_key UNIQUE (phone);


--
-- Name: customers customers_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.customers
    ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);


--
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.services
    ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);


--
-- Name: appointments appointments_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(customer_id);


--
-- Name: appointments appointments_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(service_id);


--
-- PostgreSQL database dump complete
--


Generally the text:

service_id) name Service
------------+-------)  Service

is caused by what is returned from database and when how that data is used.

Take a look for example at the $SERVICES_OFFERED, add

echo "$SERVICES_OFFERED"

Below the line with psql query. This is what it will print:

 service_id | name  
------------+-------
          1 | cut
          2 | color
          3 | trim
          4 | perm
          5 | style
(5 rows)

As it can be seen, the output uses all that information, but the end result of that is not the desired one.