Tell us what’s happening:
I’m getting the following error:
psql: error: connection to server on socket “/var/run/postgresql/.s.PGSQL.5432” failed: FATAL: role “username=freecodecamp” does not exist
Describe your issue in detail here.
I’ve tried
- Reset
- closing my browser and restarting
- instructions on this thread : https://forum.freecodecamp.org/t/unable-to-connect-to-postgres/512012/2
!/bin/bash
PSQL=“psql -X username=freecodecamp --dbname=salon --tuples-only -c”
echo $($PSQL “TRUNCATE TABLE customers, appointments”)
echo -e “\n~~~~ MY SALON ~~~~\n”
display numbered list of services offerred
MENU(){
if [[ $1 ]]
then
echo -e “\n$1”
fi
get services available
AVAILABLE_SERVICES=$($PSQL “SELECT service_id, name FROM services ORDER BY service_id)”)
echo $AVAILABLE_SERVICES
print services available
echo -e “\nWelcome to My Salon, how can I help you? \n”
echo “$AVAILABLE_SERVICES” | while read SERVICE_ID BAR SERVICE_NAME
do
echo “$SERVICE_ID) $SERVICE_NAME”
done
read service selected
read SERVICE_ID_SELECTED
if service isn’t an integer, show the same list of services again
if [[ ! $SERVICE_ID_SELECTED =~ [1]+$ ]]
then
send to main menu
MENU “I could not find that service. What would you like today?”
fi
if the service doesn’t exist, show the same services again
SERVICE_ID=$($PSQL “SELECT service_id FROM services WHERE service_id = $SERVICE_ID_SELECTED”)
if [[ -z $SERVICE_ID ]]
then
MENU “I could not find that service. What would you like today?”
fi
prompt for phone number CUSTOMER_PHONE
echo -e “\nWhat’s your phone number.”
read CUSTOMER_PHONE
get customer name
CUSTOMER_NAME = echo $($PSQL “SELECT name FROM customers WHERE phone = ‘$CUSTOMER_PHONE’”)
if phone number does not exist get customer’s name CUSTOMER_NAME, enter name and phone number
into customers table
if [[ -z CUSTOMER_NAME ]]
then
echo -e “\nPlease enter your name.”
read CUSTOMER_NAME
echo $($PSQL “INSERT INTO customers(phone, name) VALUES(‘$CUSTOMER_PHONE’, ‘CUSTOMER_NAME’)”)
fi
prompt for time SERVICE_TIME
echo -e “\nPlease enter desired appointment time.”
read SERVICE_TIME
get customer ID
CUSTOMER_ID= $($PSQL “SELECT customer_id FROM customers WHERE phone =‘$CUSTOMER_PHONE’”)
insert row into appointments
echo $($PSQL “INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, $SERVICE_TIME)”)
get service name
SERVICE_NAME = $($PSQL “SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED”)
confirmation of appointment
echo “I have you put down for a $SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME”
}
MENU
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Challenge: Salon Appointment Scheduler - Build a Salon Appointment Scheduler
Link to the challenge:
Thank you in advance.
0-9 ↩︎