Salon Appointment Scheduler - Build a Salon Appointment Scheduler

Tell us what’s happening:

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

Hi @SoFran

Which two tests are failing?

Happy coding

Hi Teller,

The tests that it is failing are these two:

  • 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.

Thanks! :slight_smile:

Hi @SoFran

Make sure all the variables in VALUES() are nested in single quote marks.

Happy coding

Hi Teller,

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.

Thanks! :slight_smile:

You used single quotes here.

But not here, where tests are failing.

Time is not always an integer:

I have put you down for a cut at 10:30, Fabio.
I have put you down for a color at 11am, Fabio.

Hi Teller,

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.

Sorry if I’m missing something…

Hi @SoFran

I was considering when $SERVICE_TIME could be an integer, as you mentioned the tests sometimes failed.

Do try using single quotes for all the VALUES() though, I suspect the tests may fail if they are not present in your code.

Hi Teller,

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 :slight_smile:

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


For now, just use values for the first test.
Post screen shots when you run the script and the tables.

Here is the image of the table once I run both tests.

Please also post the prompts and inputs when you run script, and the other tables as well.

Here are all the screenshots:



Hi @SoFran

You need these 5 services:

  1. cut
  2. color
  3. perm
  4. style
  5. trim

Happy coding

Hi ,

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.

Thanks! :slight_smile:

Try this welcome message:

Welcome to My Salon, how can I help you?

Hi,

Sorry for the wait. I’m doing this certification only during the week at work – anyways, I tried that and had no luck. Still failing.

Thanks! :slight_smile: