#!/bin/bash

source head.sh

# echo $QUERY_STRING
# QUERY_STRING="name=aa&subjectId=1"

name=$(echo $QUERY_STRING | awk -F "&" '{print $1}' | awk -F "=" '{print $2}')
name=$(python3 -c "import urllib.parse; print(urllib.parse.unquote(\"$name\"))")
subjectId=$(echo $QUERY_STRING | awk -F "&" '{print $2}' | awk -F "=" '{print $2}')

sql="INSERT INTO jx_teacher VALUES(NULL, '$name', $subjectId)"
$wmysqllogin "$sql" 
sql="select jx_teacher.id, jx_teacher.name, jx_subject.name from jx_teacher  join jx_subject on jx_teacher.subjectId=jx_subject.id;"
redis-cli -c -h $cacheaddr del "$sql"

if [ $? -eq 0 ]; then
  echo "添加成功"
  echo "<meta http-equiv="refresh" content="3\;URL=/cgi-bin/listTeacher.sh">3秒内跳转老师列表</meta>"
else
  echo "添加失败"
fi
