mysql - Unable to delete specific entry PHP -
Then I have this PHP app where you can work and delete them. The problem is that when I have more than one task, then all the deleted work links will remove the work you want to delete instead of the work you want to delete. For example, in the latest work ID = 25 I want to delete the job with id = 18, but clicking on the deleted link removes the task with id = 18.
The code for the work views is here:
while receiving ($ line = $ stmt-> (PDO :: FETCH_ASSOC)) {$ id = $ _SESSION ['id'] = $ line ['id']; $ _SESSION ['Jobs'] = $ line ['Work']; $ _SESSION ['Start'] = $ line ['Start']; $ _SESSION ['Ended'] = $ line ['Ended']; // Start a session starting for a PHP date object $ startdate = new date time ($ _ session ['start']); $ Endadet = new date time ($ _ session ['end']); // echo work property in a table print ""; Print "& lt; p & gt; & lt; a href = 'editview.php? Id = $ id' & gt; Edit Job & lt; / a & gt; | & lt; a href = 'delete.php ? Id = $ id '& gt; delete task & lt; / a & gt; & lt; / p & gt; "; Print "& lt; p & gt; Start date:" $ startdate- & gt; Format ('dm y'). "& Lt; / p & gt;"; Print "& lt; p & gt; To complete the date:". $ Enddate-> Format ('dm y'). "& Lt; / p & gt;"; Print "& lt; p & gt;". $ _ Session ['work'] & Lt; / P & gt; "; Print" & lt; / Div & gt; ";} and the deletion function here is being called (this also happens with the edit function, but these are both the same problem): To delete the work from the session_start (); // work table, type $ query = "remove id from id =?"; // to specify ID id = $ _SESSION [' Id '] Assign ID; Try // // Generate query $ stmt = $ dbh- & gt; Ready ($ query); // id table value variable id $ stmt- & gt; BindParam (1, $ Id) Take; $ Stmt- & gt; Execute ();}
You have a link Is:
& lt; A href = 'delete.php? Id = $ id' & gt;
To get an ID that you Get it from $ _ GET
not $ _ session
) $ Query = "Where to remove id from id =?"; / / Id to id = $ id = $ _GET ['id'];
And avoid sessions in your loop, it is not necessary:
< Code> while ($ line = $ stmt-> Get (PDO :: FETCH_ASSOC)) {$ Id = $ line ['id']; // Start a session in a PHP date object $ startdate = new date time ($ line ['start']); $ End = new date time ($ line ['end']); // echo work properties in a table print ""; Print "& lt; p & gt; & lt; a href = 'editview.php? Id = $ id' & gt; Edit Job & lt; / a & gt; | & lt; a href = 'delete.php ? Id = $ id '& gt; delete task & lt; / a & gt; & lt; / p & gt; "; Print "& lt; p & gt; Start date:" $ startdate- & gt; Format ('dm y'). "& Lt; / p & gt;"; Print "& lt; p & gt; To complete the date:". $ Enddate-> Format ('dm y'). "& Lt; / p & gt;"; Print "& lt; p & gt;" $ Line ['work'] "& Lt; / p & gt;"; Print "& lt; / div & gt;"; }
Comments
Post a Comment