A simple Flask web application that allows users to submit student information through a web form and stores the data in a SQL Server database.
- Clean web interface for entering student details
- Real-time form submission with success/error feedback
- SQL Server database integration
- Input validation and parameterized queries for security
Before running this application, make sure you have:
- Python 3.7 or any big version
- SQL Server
- ODBC Driver 17 for SQL Server(SSMS)
-
Clone the repository
cd student-database -
Create a virtual environment
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Create the database
- Open SQL Server Management Studio (SSMS)
- Create a new database named
Students
-
Create the table
USE Students; CREATE TABLE dbo.Students_data ( id INT IDENTITY(1,1) PRIMARY KEY, name NVARCHAR(100) NOT NULL, class NVARCHAR(50) NOT NULL, roll_no INT NOT NULL, subject NVARCHAR(100) NOT NULL, created_at DATETIME DEFAULT GETDATE() );
-
Environment Variables (Recommended)
- Copy
.env.exampleto.env - Update the database connection details in
.env:
DB_SERVER=localhost DB_NAME=Students DB_TRUSTED_CONNECTION=yes - Copy
-
Direct Configuration (Alternative)
- If not using environment variables, update the connection string in
app.py:
conn_str = ( "DRIVER={ODBC Driver 17 for SQL Server};" "SERVER=your_server_name;" "DATABASE=Students;" "Trusted_Connection=yes;" )
- If not using environment variables, update the connection string in
-
Test database connection
python connection.py
You should see:
✅ Connected to database: Students -
Start the Flask application
python app.py
-
Access the application
- Open your web browser
- Navigate to
http://localhost:5000 - Fill out the student form and submit
The application provides a simple form with the following fields:
- Name: Student's full name
- Class: Student's class/grade
- Roll No: Student's roll number (numeric)
- Subject: Subject name
After submission, the data is stored in the SQL Server database and a success message is displayed.
student-database/
│
├── app.py # Main Flask application
├── connection.py # Database connection test
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # This file
-
Database Connection Failed
- Ensure SQL Server is running
- Verify server name and database name
- Check if ODBC Driver 17 is installed
-
ODBC Driver Not Found
- Download and install Microsoft ODBC Driver 17 for SQL Server
-
Permission Denied
- Ensure your Windows user has access to SQL Server
- Or configure SQL Server authentication with username/password
To allow access from other devices on your network:
app.run(host='0.0.0.0', port=5000, debug=True)- Input validation is implemented through parameterized queries
- For production deployment:
- Set
debug=False - Use HTTPS
- Implement proper authentication
- Add CSRF protection
- Use environment variables for all sensitive data
- Set
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
This project is open source .
If you encounter any issues or have questions, please:
- Check the troubleshooting section above
- Search existing issues on GitHub
- Create a new issue with detailed information about your problem
- Add data validation on the frontend
- Implement student data viewing/editing functionality
- Add search and filter capabilities
- Export data to CSV/Excel
- Add user authentication
- Implement RESTful API endpoints