0

How can I avoid the DELETE method giving me a 405 error? Is there any way to delete rows from my database?

I've tried including the following in the web.config file in my root directory, but this doesn't work.

<system.webServer>    
  <modules>        
    <remove name="WebDAVModule" />    
  </modules>    
  <handlers>        
    <remove name="WebDAV" />    
  </handlers>
</system.webServer>

I've included code snippets below for reference.

HTML:

         <form method = "post" class= "my-5 text-center">
            <caption>Remove Staff</caption>
                <select name="staff" style="width: 300px">
                    <option></option>
                        {% for p in people %}
                            <option name="staff">{{ p.name }}</option>
                        {% endfor %}
                    </select>
            <input type= "submit"/>
        </form>

python:

@app.route("/deletestaff")
def deletestaff():
    if request.method == "POST":
        name = request.form.get("name")
        db.execute("DELETE * FROM staff WHERE id=1")
        people = db.execute("SELECT name, id FROM staff")
        return render_template("deletestaff.html", people=people)
    else:
        people = db.execute("SELECT name, id FROM staff")
        return render_template("deletestaff.html", people=people)
Simon
  • 325
  • 1
  • 13

2 Answers2

0

The syntax you need to delete a row is as follows;

DELETE FROM table_name WHERE condition;

So try changing your db.execute to the following;

"DELETE FROM staff WHERE id=1"

Please see this guide for more information

Simon
  • 325
  • 1
  • 13
  • 1
    It's the DELETE method that doesn't work. I just need to find a work around. Maybe I just need to store my data another way... – b-hintz May 04 '20 at 20:25
0

I figured out a workaround with the UPDATE method. Added an "active" field with a default value set to "true". Items remain in my database, but I can now Select them based on their active value, and set that value to 'false' in order to deactivate a row.