0

all.

I have a project with a table (code below). In the last column I have a 'delete' href that leads to a php page with code below. For a reason the header('location: ') does not work. The rest of the page does work fine.

The table is a part of my index page. Is this the problem? When i use the same line on other pages it works just fine.

Any suggestions here?

Tnx

table-body:

    <tbody>
        <?php                       
        foreach($todo as $todos){
        echo"<tr>";     
        echo"<td>".$todos['title']."</td>";                         
        echo"<td>".$todos['description']."</td>";
        echo"<td>".$todos['categorie']."</td>"; 
        echo "<td><a href=account.php?page=editTodo".$todos['id']."><i class='fa fa-fw fa-edit'></i></a></td>";               
        echo "<td><a href=account.php?page=delTodo".$todos['id']."><i class='fa fa-fw fa-trash'></i></a></td>";                 
        echo "</tr>";
        }
    ?>                                                                          
</tbody>

php page:

 <?php
$var_value = $_SESSION['varname'];

if (isset($_SESSION['varname'])){

    $id = $_SESSION['varname'];
    $sql = "DELETE FROM todo WHERE id = '$id'";


    $query = $conn->prepare( $sql );
    if ($query == false) {
     print_r($conn->errorInfo());
     die ('Erreur prepare');
    }
    $sth = $query->execute();
    if ($sth == false) {
     print_r($query->errorInfo());
     die ('Erreur execute');
    }

}

header('Location: http://localhost:8888/CasinoAPP/admin/index.php'); 

?>
  • 1
    How does it not work? What debugging have you done? Is error reporting on and set to show notices? – John Conde Jun 06 '18 at 11:49
  • if you put directly http://localhost:8888/CasinoAPP/admin/index.php to your browser, does it work ? – Simos Fasouliotis Jun 06 '18 at 11:51
  • If I put it directly in my browser it works just fine – Steven Mees Jun 06 '18 at 11:52
  • @StevenMees Are you going to answer my questions? Or should we close this question as unclear or a duplicate of the most likely cause for your problem? – John Conde Jun 06 '18 at 11:57
  • Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Jun 06 '18 at 12:02
  • Sorry John, I'm a newbie concerning php. I tried to put a echo 'hallo'; before the line to make sure it gets to that code, and that works fine. I don't know how to do more debugging at this moment concerning this problem. – Steven Mees Jun 06 '18 at 12:03
  • 1
    See @RiggsFolly's comment above. That should tell you a lot. – John Conde Jun 06 '18 at 12:05
  • Thanks RiggsFolly and John Conde, That already helps: now i get the following error: Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/CasinoAPP/admin/account.php:16) in /Applications/MAMP/htdocs/CasinoAPP/admin/template-pages/delTodo.php on line 26 – Steven Mees Jun 06 '18 at 12:10
  • This is a common error and the question this is linked to will show you how to debug it. – John Conde Jun 06 '18 at 12:17
  • Thanks for the help. The debug option helped a lot. I will try to find the solution on myself now. Topic Closed! – Steven Mees Jun 06 '18 at 12:20

1 Answers1

-2

There's a space before the opening <?php tag. You're probably getting an "output already sent" error!

Ben Hillier
  • 2,126
  • 1
  • 10
  • 15
  • This is just a guess and that could be just a cut and paste error when posting the question. Additionally, if this was the case, this question should be closed as a [dupe](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) and not answered. – John Conde Jun 06 '18 at 11:55
  • If the OP had told us the error message then no-one would have to guess. As it stands, guessing is all we can do! – Ben Hillier Jun 06 '18 at 11:56
  • 1
    If you have to guess because the question isn't clear enough than the question is off-topic and should be closed. – John Conde Jun 06 '18 at 11:57
  • Thanks for the suggestion Ben, but that didnt solve it unfortainlly – Steven Mees Jun 06 '18 at 12:06