0

I wrote a code it is like a todolist, before it was working, but right now normal buttons are working but the type image buttons are not working. What is wrong with it?

Up part:

if (isset($_POST['remove_list'])){
    echo("xxx");
$todo_id = $_POST['remove_list'];   //get that submit value.
$sql="DELETE FROM todo WHERE todo_id='$todo_id'"; //that users book
mysqli_query($conn,$sql);
}

if (isset($_POST['add_list'])){
    echo("yyy");
    $todo_text=$_POST['text'];
    $sql = "insert into todo(todo_text) values('$todo_text')";
    mysqli_query($conn, $sql);
    
}

Bottom form part:

<form form method="post" action="admin.php?id=anasayfa">
    <table>
        
    <?php 
        
    $todosql="SELECT * from todo";
    $resulttodo= mysqli_query($conn, $todosql);
    $i=1; 
    while ($todo=mysqli_fetch_assoc($resulttodo)){


    ?>
    <tr>
    <td>
    <?php if ($todo['todo_checked']==1){ ?>
        <input type="image" src="images/admin/checked.png" border="0" alt="Submit" name="not_check" height="20"  value="<?php echo($todo['todo_id']);?>">
    <?php
    }
    else { ?>
        <input type="image" src="images/admin/success.png" border="0" alt="Submit" name="check" height="20"  value="<?php echo($todo['todo_id']);?>">
    <?php
    }
    ?>         
    </td> 
    <td><?php echo($todo['todo_text']); ?></td><td><input type="image" src="images/admin/cancel.png" border="0" alt="Submit" name="remove_list" height="20" value="<?php echo($todo['todo_id']);?>"></td>
    </tr>
        
        
    <?php } ?>  
        
    </table>
    <input type="text" name="text" >
<input type="submit" name="add_list" value="Ekle">
</form>

Thanks for your help.

Sevval Kahraman
  • 1,185
  • 3
  • 10
  • 37

1 Answers1

1

First, please consider securing your upload code :

Next, you're using input type="image" along with input type="submit". Since input type="image" also submit the form, please use only one submit button.

Also value="<?php echo($todo['todo_id']);?>"is useless since value of image buttons do not accept value attributes, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/image

And first of all, submit button name are never send, so if (isset($_POST['add_list'])) will always return false. See Send value of submit button when form gets posted

L. Klein
  • 106
  • 1
  • 2