#!/bin/bash

source head.sh

# echo $QUERY_STRING
# QUERY_STRING="stuId=1&testId=1&subjectId=1&score=88"

stuId=$(echo $QUERY_STRING | awk -F "&" '{print $1}' | awk -F "=" '{print $2}')
testId=$(echo $QUERY_STRING | awk -F "&" '{print $2}' | awk -F "=" '{print $2}')
subjectId=$(echo $QUERY_STRING | awk -F "&" '{print $3}' | awk -F "=" '{print $2}')
score=$(echo $QUERY_STRING | awk -F "&" '{print $4}' | awk -F "=" '{print $2}')

sql="INSERT INTO jx_score VALUES(NULL, $stuId, $testId, $subjectId, $score)"
$wmysqllogin "$sql" 
sql="select jx_score.id, jx_stu.name, jx_test.name, jx_subject.name, jx_score.score  from jx_score  join jx_stu on jx_score.stuId=jx_stu.id  join jx_test on jx_score.testId=jx_test.id  join jx_subject on jx_score.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/listScore.sh">3秒内跳转成绩列表</meta>"
else
  echo "添加失败"
fi
