#!/bin/bash

source head.sh

# echo $QUERY_STRING
# QUERY_STRING="name=aa&age=18&classId=2"

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

sql="INSERT INTO jx_stu VALUES(NULL, '$name', $age, $classId)"
$wmysqllogin "$sql" 

sql="select jx_stu.id, jx_stu.name, jx_class.name, jx_stu.age from jx_stu join jx_class on jx_stu.classId=jx_class.id;"
redis-cli -c -h $cacheaddr del "$sql"

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