我想做一个像按钮,但这是不起作用的PHP mysql

this is my code but it does not work I want a code that makes a like button for every img and if they press a button the need for waarde + 1 is to be done. but why does this code not work, he connects it well with the database but he does not do anything waarde +1

what he is doing now he increases the value of the first row in the database and it does not matter which button you click

$sql="SELECT url, categorie FROM url";
if ($result=mysqli_query($conn,$sql))
{
    while ($row=mysqli_fetch_row($result)) {
        $url = $row[0];
?>
         <div class="col-12 col-sm-6 col-lg-3 isotope-item <?php echo $row[1]; ?>">
             <div class="image-gallery-item mb-4 pb-3">
                 <a href="<?php echo $row[0]; ?>" class="lightbox-portfolio">
                     <span class="thumb-info custom-thumb-info-1">
                         <span class="thumb-info-wrapper">
                             <span class="thumb-info-plus"></span>
                             <img src="<?php echo $row[0]; ?>" class="img-fluid" alt="">
                            <form action="" method="POST"> 
                                <button type="submit" value="<?php echo $url;?>" class="btn-floating  waves-effect waves-dark transparent" name="like">
                                    <i class="material-icons blue-text">thumb_up</i>
                                </button>
                            </form>

                         </span>
                     </span>
                 </a>
             </div>
         </div>                          

<?php 
}

    if(isset($_POST['like'])){
        $sql = "UPDATE url SET waarde = waarde + 1 WHERE url = '".$url."'";

        if ($conn->query($sql) === TRUE) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . $conn->error;
        }
        $conn->close();
    } 

    mysqli_free_result($result);
} 
mysqli_close($connection); 
?>

can somebody help me?

Change this:

if(isset($_POST['like'])){
        $sql = "UPDATE url SET waarde = waarde + 1 WHERE url = '".$url."'";

into this:

if(isset($_POST['like'])){
        $value = $_POST['like'];
        $sql = "UPDATE url SET waarde = waarde + 1 WHERE url = '$value'";

so you are parametrizing your query to the url that have been posted.

Two side notes:

  • the update query should be out of the while loop. It is not necessary to repeat it several times;
  • you should not have the same name for a table (url) and a field in the table (url). It is not a good practice at least for readibility and can lead to issues in the query if you don't specify always the table name like url.url