Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete button for each table row

Tags:

php

button

I manage to succesfully read and display data from my database with the following code: http://pastebin.com/rjZfBWZX I also generate a delete button for each row of the table :) Clicking the delete button calls "obrisi.php" which is supposed to delete that row but I messed something up :S Here's obrisi.php code:

http://pastebin.com/mrFy1i7S

I'm getting a Parse error: syntax error, unexpected 'FROM' (T_STRING) :S

like image 686
Singed Avatar asked Jan 14 '23 13:01

Singed


1 Answers

Let's try and do it with _GET instead of _POST.

In your main code you need to change line 39 (the input) from:

    echo  "<td>" . " <input type='submit' id= '$id' . ' value='Delete' >" .  "</td>";

to:

    echo  "<td><a href='obrisi.php?id=$id'>Delete</a></td>";

In your obrisi.php change line 3 (the id setup) from:

    $id = $_POST['id'];

to:

    $id = $_GET['id'];

And finally as a nice addition, redirect back to the main page by adding the following line at the end of the obrisi.php file before the closing of the php tag.

    header('location:index.php');

Where index.php the name of the main page you have.

like image 156
Thanasis Pap Avatar answered Jan 21 '23 20:01

Thanasis Pap