Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am expriencing a problem in my code espcially with this part of the code
ERROR DESCRIPTION: mysql.connector.errors.DataError: 1292 (22007): Truncated incorrect DOUBLE value: '2018-1157'
http://127.0.0.1:8080/student/delete/2018-1158
href="http://127.0.0.1:8080/student/delete/2018-1158" target="_blank" title="New Window">^]
@student_bp.route("/student/delete/<string:school_id>", methods=['GET','POST'])
def delete(school_id):
    cursor = mysql.connection.cursor()
    sql = f"DELETE from student where school_id= {school_id}"
    cursor.execute(sql)
    mysql.connection.commit()
    flash("Slot Deleted Successful","danger")
    return redirect('student')


What I have tried:

@student_bp.route("/student/delete/<string:school_id>", methods=['GET','POST'])
def delete(school_id):
    cursor = mysql.connection.cursor()
    sql = f"DELETE from student where school_id= {school_id}"
    cursor.execute(sql)
    mysql.connection.commit()
    flash("Slot Deleted Successful","danger")
    return redirect('student')
Posted
Updated 9-Nov-22 6:25am
Comments
Richard Deeming 10-Nov-22 6:29am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

Python MySQL Execute Parameterized Query using Prepared Statement[^]

1 solution

The value you are passing to the delete method looks like a number. You need to pass it as a string type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900