我们提供学生信息管理系统招投标所需全套资料,包括学工系统介绍PPT、学生管理系统产品解决方案、
学生管理系统产品技术参数,以及对应的标书参考文件,详请联系客服。
CREATE TABLE Students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
age INT,
major VARCHAR(100)
);
CREATE TABLE Courses (
id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(100) NOT NULL,
teacher_name VARCHAR(100)
);
CREATE TABLE Assignments (
id INT AUTO_INCREMENT PRIMARY KEY,
assignment_name VARCHAR(100) NOT NULL,
due_date DATE,
student_id INT,
FOREIGN KEY (student_id) REFERENCES Students(id)
);
from flask import Flask, request, jsonify
from flask_mysqldb import MySQL
app = Flask(__name__)
# 配置MySQL
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'school_management'
mysql = MySQL(app)
@app.route('/students', methods=['POST'])
def add_student():
data = request.get_json()
name = data['name']
age = data['age']
major = data['major']
cur = mysql.connection.cursor()
cur.execute("INSERT INTO Students (name, age, major) VALUES (%s, %s, %s)", (name, age, major))
mysql.connection.commit()
cur.close()
return jsonify({"message": "Student added successfully"}), 201
Add Student
document.getElementById('studentForm').addEventListener('submit', function(event){
event.preventDefault();
const name = document.getElementById('name').value;
const age = document.getElementById('age').value;
const major = document.getElementById('major').value;
fetch('/students', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name, age, major})
})
.then(response => response.json())
.then(data => alert(data.message));
});