I want the data to be deleted from my database and table when the delete button next to the Doctor in the table in the codes I wrote below is clicked.
Can you help me how can I do it?
<div class="sil">
<h1>Doktor Sil</h1>
<form action="#">
<table class="table table-striped">
<thead>
<tr>
<td scope="col">Doktor ID</td>
<td scope="col">Ad</td>
<td scope="col">Soyad</td>
<td scope="col">Uzmanlık Alanı</td>
<td scope="col">Telefon</td>
<td scope="col">Doğum Tarihi</td>
<td scope="col">-</td>
</tr>
</thead>
<tbody>
{% for doktor in doktorlar %}
<tr>
<td >{{doktor[0]}}</td>
<td>{{doktor[1]}}</td>
<td>{{doktor[2]}}</td>
<td>{{doktor[4]}}</td>
<td>{{doktor[5]}}</td>
<td>{{doktor[6]}}</td>
<td>
<a href="admin_panel_menu/{{panel_id}}/sil/{{doktor[0]}}"><button type="submit"> - Sil - </button></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
@app.route('/admin_panel_menu/<panel_id>')
def admin_panel_menu(panel_id):
# content_id'ye göre ilgili içeriği gönder
if panel_id == 'Doktor':
doktorlar = Doktor.doktor_goster()
return render_template('d_admin.html', doktorlar = doktorlar)
if panel_id == 'Hasta':
return render_template('h_admin.html')
if panel_id == 'Rapor':
return render_template('r_admin.html')
def doktor_goster():
conn = sqlite3.connect('hospital.db')
c = conn.cursor()
c.execute("SELECT * FROM Doktorlar")
doktor = c.fetchall()
conn.close()
return doktor
def doktor_sil(doktor_id):
conn = sqlite3.connect('hospital.db')
c = conn.cursor()
c.execute("DELETE FROM Doktorlar WHERE id = {0}".format(id))
conn.commit()
conn.close()
I want to use the doctor_delete function here.
New contributor
Richpoort123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.