0

I am creating a simple blog but I don't manage to make the delete button work. I think I am missing out on the button? I am well aware of SQL INJECTION and PREPARED STATEMENTS. I will be dealing with them later. There are no errors with connection. My delete query is in a function deleteArticles() on this page: articles.sql.php

    // DELETE
function deleteArticle($c){

    $item = $_GET['item'];

    $qryDeleteArt = 'DELETE FROM articles
                     WHERE artID = \''.$item.'\'';
    if (!mysqli_query($c,$qryDeleteArt))
  {
  die('Error: ' . mysqli_error($c));
  } echo 'success';


}

    // CONTROLER //
switch( $action ){

    case 'insert' : 
        $process = insertArticle($conn);    
        if( $process == 'ok' ) 
            header( 'location:index.php?page=home' );
        else 
            $page = 'articleform';
        break;

    case 'update' : 
        $process = updateArticle($_GET[ 'item' ]);  
        if( $process == 'ok' ) 
            header( 'location:index.php?page=home' );
        else 
            $page = 'articleform';
        break;

    case 'delete' : 
        $process = deleteArticle( $conn, $_GET[ 'item' ] ); 
        if( $process == 'ok' ) 
            header( 'location:index.php?page=home' );
        break;
}

?>

Form is on this page: home.php

<div class="article">
      <h3>
       <?php 
       while($rows = mysqli_fetch_array($rArticles)){ 
       ?>
       <a href="index.php?page=articleform&article="><?php  echo $rows['artTitre'];  ?></a>

        <span><a class="btn" href="index.php?page=articles&action=delete&item=">supprimer</a></span>
        </h3>
        <p><em><?php  echo $rows['artDate'];  ?> - <?php  echo $rows['artAuteur'];  ?></em></hp>
        <p><?php  echo $rows['artContenu'];  ?></p> 

1 Answer 1

1

I can't find sending the item_id in your href's
Try adding this:

<a class="btn" href="index.php?page=articles&action=delete&item=<?=$rows['itemID']?>">  
<a class="btn" href="index.php?page=articleform&article=<?=$rows['artID']?>">  

instead of your current links

Sign up to request clarification or add additional context in comments.

8 Comments

@Ivil , I am having syntax error : Error: Erreur de syntaxe près de 'artID'];?>'' à la ligne 2
post the full code you are using, the message you gave cannot exist if you copied the code lvil supplied. He is not using the semicolon after the artId'] which dóes exist in your error message.
<span><a class="btn" href="index.php?page=articles&action=delete&item=<?=$rows['artID']?>">supprimer</a></span>
I think it has something to do with my query?
$qryDeleteArt = 'DELETE FROM articles WHERE artID = \''.$item.'\'';
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.