The script that I am working on does what it should in terms of the database. However, the tests will not pass and I have tried everything I can think of. It is stuck on the two tasks which require entry.
Your code so far
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
# display title
echo -e "\n~~~~~ SALON ~~~~~\n"
echo -e "Welcome to Salon, how can I help you?\n"
# get services
SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
MAIN_MENU() {
# display argument if exist
if [[ $1 ]]
then
echo -e "\n$1"
fi
echo -e "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
SERVICE_ID=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")
if [[ -z $SERVICE_ID ]]
then
MAIN_MENU "That service does not exist. Please try again."
return
else
SERVICE_NAME=$($PSQL "SELECT name from services WHERE service_id=$SERVICE_ID")
# ask for phone number
echo -e "\nWhat is your phone number?"
read CUSTOMER_PHONE
# look up customer name from phone number in database
CUSTOMER_NAME=$($PSQL "SELECT name from customers WHERE phone='$CUSTOMER_PHONE'")
# if doesn't exist
if [[ -z $CUSTOMER_NAME ]]
then
# ask customer name
echo -e "\nWhat is your name?"
read CUSTOMER_NAME
INSERT_INTO_CUSTOMERS=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
# ask for time
echo -e "\nWhat time would you like to schedule for?"
read SERVICE_TIME
if [[ -z $SERVICE_TIME ]]
then
MAIN_MENU "A service time is required. Please try again."
return
else
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
INSERT_APPOINTMENT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")
if [[ $INSERT_APPOINTMENT=='INSERT 0 1' ]]
then
echo -e "\nI have put you down for a $(echo $SERVICE_NAME | sed -r 's/^ *| *$//g') at $(echo $SERVICE_TIME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')."
exit
fi
fi
fi
}
MAIN_MENU
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Salon Appointment Scheduler - Build a Salon Appointment Scheduler
You can create a row in the appointments table by running your script and entering 1, 555-555-5555, Fabio, 10:30 at each request for input if that phone number isn’t in the customers table. The row should have the customer_id for that customer, and the service_id for the service entered
You can create another row in the appointments table by running your script and entering 2, 555-555-5555, 11am at each request for input if that phone number is already in the customers table. The row should have the customer_id for that customer, and the service_id for the service entered
I have had numerous issues with things getting checked off for this practice build. Often they pass and I get a check then I edit something below that and for no reason they get unchecked over and over again. So I’m kind of lost at this point.
I think that I just did that and still no good. I’m assuming that you mean all the values that are getting plugged into the final insert statement. However, aren’t those supposed to be integers so they wouldn’t require single quotes except for the SELECT_TIME which would.
I’m not sure what you mean. The $SERVICE_TIME does have quotes around it in the failing line. So, it is not being taken in as an integer but as a string. So, I’m not sure what you mean. $CUSTOMER_ID and $SERVICE_ID_SELECTED are the only ones that I have as integers for that.
Ah that makes more sense. The two we are discussing are always failing. The ones that sometimes were were ones that I have already cleared – I just wanted to point out that sometimes there are other sections that work and then fail with a small edit – it was a tangent. Sorry about that.
I tried to use single quotes for all the values in that insert statement and had the same result unfortunately.
Thanks
Here is the revised code that I had tried but that also failed:
#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
# display title
echo -e "\n~~~~~ SALON ~~~~~\n"
echo -e "Welcome to Salon, how can I help you?\n"
# get services
SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
MAIN_MENU() {
# display argument if exist
if [[ $1 ]]
then
echo -e "\n$1"
fi
echo -e "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
SERVICE_ID=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")
if [[ -z $SERVICE_ID ]]
then
MAIN_MENU "That service does not exist. Please try again."
return
else
SERVICE_NAME=$($PSQL "SELECT name from services WHERE service_id=$SERVICE_ID")
# ask for phone number
echo -e "\nWhat is your phone number?"
read CUSTOMER_PHONE
# look up customer name from phone number in database
CUSTOMER_NAME=$($PSQL "SELECT name from customers WHERE phone='$CUSTOMER_PHONE'")
# if doesn't exist
if [[ -z $CUSTOMER_NAME ]]
then
# ask customer name
echo -e "\nWhat is your name?"
read CUSTOMER_NAME
INSERT_INTO_CUSTOMERS=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
# ask for time
echo -e "\nWhat time would you like to schedule for?"
read SERVICE_TIME
if [[ -z $SERVICE_TIME ]]
then
MAIN_MENU "A service time is required. Please try again."
return
else
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
INSERT_APPOINTMENT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES('$CUSTOMER_ID', '$SERVICE_ID_SELECTED', '$SERVICE_TIME')")
if [[ $INSERT_APPOINTMENT=='INSERT 0 1' ]]
then
echo -e "\nI have put you down for a $(echo $SERVICE_NAME | sed -r 's/^ *| *$//g') at $(echo $SERVICE_TIME | sed -r 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')."
exit
fi
fi
fi
}
MAIN_MENU
I tried that and that didn’t work either. There is no indication for those 5 items to be included in the instructions. Hence why I missed them. Is there a way to flag that for freecodecamp. Because if that is supposed to be an instruction that is a pretty significant missing part of their instructions.
Hence why my 3rd was nails and not any of the others. The color as 2 was just a coincidence.