Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-362
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-362
2023-362
Commits
f1fa42ae
Commit
f1fa42ae
authored
Oct 23, 2023
by
Nirmal M.D.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created insertTask.py
parent
698a53a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
IT20074340/TaskAllocation/Sachintha/model/insertTask.py
IT20074340/TaskAllocation/Sachintha/model/insertTask.py
+54
-0
No files found.
IT20074340/TaskAllocation/Sachintha/model/insertTask.py
0 → 100644
View file @
f1fa42ae
from
flask
import
Flask
,
request
,
jsonify
import
mysql.connector
from
flask_cors
import
CORS
app
=
Flask
(
__name__
)
CORS
(
app
,
resources
=
{
r"/*"
:
{
"origins"
:
"*"
}})
# MySQL Database Configuration
db_config
=
{
'host'
:
'localhost'
,
'user'
:
'root'
,
'password'
:
''
,
'database'
:
'rptestdb'
,
}
# Route to handle data submission
@
app
.
route
(
'/submit_data'
,
methods
=
[
'POST'
])
def
submit_data
():
try
:
data
=
request
.
json
# Assuming data is sent in JSON format
title
=
data
[
'title'
]
description
=
data
[
'description'
]
level
=
data
[
'level'
]
print
(
title
)
print
(
description
)
print
(
level
)
# Establish a connection to the MySQL database
try
:
db_connection
=
mysql
.
connector
.
connect
(
**
db_config
)
cursor
=
db_connection
.
cursor
()
except
mysql
.
connector
.
Error
as
err
:
print
(
f
"Error: {err}"
)
cursor
=
None
# Insert data into the database
insert_query
=
"INSERT INTO task (title, description, level) VALUES (
%
s,
%
s,
%
s)"
values
=
(
title
,
description
,
level
)
cursor
.
execute
(
insert_query
,
values
)
db_connection
.
commit
()
cursor
.
close
()
db_connection
.
close
()
return
jsonify
({
'message'
:
'Data inserted successfully'
})
except
Exception
as
e
:
return
jsonify
({
'error'
:
str
(
e
)})
if
__name__
==
'__main__'
:
app
.
run
(
host
=
'127.0.0.1'
,
port
=
5002
,
debug
=
False
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment