Salon Appointment Scheduler - Build a Salon Appointment Scheduler

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

please post a screenshot of what is happening.
also please indicate if you have tried to run the Reset button and what was the result

Hi, thank you for your response. I have reset with no change. I have provided screenshots of the run scripts and data inserted into tables. Please let me know if there is any more information you require. Best regards.

i noticed you may have extra space character in front of the words cut and color. Maybe try removing any extra spaces in your interface to see if that helps.

Hi, thanks for the tips. Done and also noticed I had left out a “?”. Also noticed there were some duplicates in my script so I changed it. Still no joy. Thanks for your time, I realoly appreciate it.
Below is the new script and below that screenshots of run script and db data:

#!/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

SERVICE_NAME_FORMATTED=$(echo $SERVICE_NAME_SELECTED | sed -r ‘s/^ *| *$//g’)

BOOKING_MENU

fi

fi

}

BOOKING_MENU(){

#get customer details

echo -e “\nWhat’s your phone number?”

read CUSTOMER_PHONE

CUSTOMER_PHONE_CHECK=$($PSQL “SELECT name FROM customers WHERE phone = ‘$CUSTOMER_PHONE’”)

if [[ -z $CUSTOMER_PHONE_CHECK ]]

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’)”)

fi

CUSTOMER_NAME=$($PSQL “SELECT name FROM customers WHERE phone = ‘$CUSTOMER_PHONE’”)

CUSTOMER_NAME_FORMATTED=$(echo $CUSTOMER_NAME | sed -r ‘s/^ *| *$//g’)

#get booking time

echo -e “\nWhat time would you like your $SERVICE_NAME_FORMATTED, $CUSTOMER_NAME_FORMATTED?”

read SERVICE_TIME

#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_FORMATTED at $SERVICE_TIME, $CUSTOMER_NAME_FORMATTED.”

}

MAIN_MENU

You should share the schema of all the tables as well in case there is anything there to fix

Also the instructions say that your script should end after each task. I think your script just returns to the main menu at the end? So I would fix that.

But wouldn’t the last task fail as well in that case?

Please see below table schemas. Busy checking the exit issue. Thanks a million.
Screenshot_4

my reading of the instructions tells me that as soon as you complete the last task of outputing the message that confirms the appointment you should exit the program.

Hi, apologies for late response, we had a large scale power outage. I am at a loss. I dropped the db and rebuilt it, double checking requirements. All correct. I added exit after the final message. What I don’t get is: the test requirement for each step is that a record is inserted into the relevant table with the correct data. Both steps do as required. Maybe it’s the wording of the requirement I am not understanding. The exit stipulation is in the final test requirement that passes fine. I just don’t get it! Anyway, below is my edited script and db info. Thank you for your continued assistance. I forgot to screenshot table data after first run but it had the correct first row.

#!/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

SERVICE_NAME_FORMATTED=$(echo $SERVICE_NAME_SELECTED | sed -r 's/^ *| *$//g')

BOOKING_MENU

fi

fi

}

BOOKING_MENU(){

#get customer details

echo -e "\nWhat's your phone number?"

read CUSTOMER_PHONE

CUSTOMER_PHONE_CHECK=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")

if [[ -z $CUSTOMER_PHONE_CHECK ]]

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')")

fi

CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")

CUSTOMER_NAME_FORMATTED=$(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')

#get booking time

echo -e "\nWhat time would you like your $SERVICE_NAME_FORMATTED, $CUSTOMER_NAME_FORMATTED?"

read SERVICE_TIME

#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_FORMATTED at $SERVICE_TIME, $CUSTOMER_NAME_FORMATTED."

exit 0

}

MAIN_MENU

I can only put one embedded image at a time so here is the second one.
Screenshot_9

can you try this:

(change varchar length on time from 5 to 10)

1 Like

Thank you I had the same problem and it worked for me :slight_smile:

1 Like

I’m just finishing off the number guessing game but will give this a bash as soon as I am done. You are a superstar, thanks a million for your time and effort. I will post outcome here. Thanks again, I really appreciate it.

2 Likes

Something told me to take a break and give your suggestion a try now. It worked. Wow, you are the best. That is quite a freaky one, must have taken you a lot of blood, sweat and tears to figure that one out. That is a curve ball, all the data provided in the test was max 5 with no stipulation to allow for more. Anyway, have yourself an amazing weekend, your’e enabling me to have a magic one. Best regards.

1 Like

we got lucky that someone else on the forum had discovered the fix. I just searched for previous posts in 2024 that had the same issue.
Happy things worked for you.