Tell us what’s happening:
In the Salon appointment scheduler project it refuses to pass on the two insert into db tasks. When I check the db, the records are there exactly as required. I don’t understand it. Please could someone assist. Thank you.
### Your code so far
#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n~~~~~ My Salon ~~~~~\n"
MAIN_MENU(){
if [[ $1 ]]
then
echo -e "\n$1"
fi
#get services
AVAILABLE_SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
#if services empty
if [[ -z $AVAILABLE_SERVICES ]]
then
MAIN_MENU "System error."
else
#display services
echo "$AVAILABLE_SERVICES" | while read SERVICE_ID BAR NAME
do
echo "$SERVICE_ID) $NAME"
done
#selected service
read SERVICE_ID_SELECTED
#if invalid input
SERVICE_NAME_SELECTED=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
if [[ -z $SERVICE_NAME_SELECTED ]]
then
MAIN_MENU "I could not find that service. What would you like today?"
else
BOOKING_MENU
fi
fi
}
BOOKING_MENU(){
#get customer details
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
if [[ -z $CUSTOMER_NAME ]]
then
#get customer name
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
#add new customer to db
INSERT_CUSTOMER_DETAILS=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$CUSTOMER_PHONE')")
#get booking time
echo -e "\nWhat time would you like your $SERVICE_NAME_SELECTED, $CUSTOMER_NAME"
read SERVICE_TIME
else
#get booking time
echo -e "\nWhat time would you like your $SERVICE_NAME_SELECTED, $CUSTOMER_NAME"
read SERVICE_TIME
fi
#get customer id
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
#insert booking
INSERT_BOOKING_DETAILS=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")
echo -e "\nI have put you down for a $SERVICE_NAME_SELECTED at $SERVICE_TIME, $CUSTOMER_NAME."
}
MAIN_MENU
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
Salon Appointment Scheduler - Build a Salon Appointment Scheduler