I have a form that shows images whos paths are stored in mysql. The form has 'hide' and 'show' submit buttons for each image. Pressing the hide button should set the value of the 'status' field to 2 (hidden). But it does nothing, my queries don't seem to execute.

Here is the form

<form  class="removeform"action='headerimageadd.php'  method='post' enctype='multipart/form-data' name='image_remove_form' > 
         <?php
         include '../inc/connect.php';
         $q = "SELECT * FROM headerrotatorimage WHERE rotator = 1";
         $result = $link->query($q);
         while($row=mysqli_fetch_array($result)){
            echo "<input type='submit' name='hide[{$row['id']}]' value='Hide'>",
                 "<input type='submit' name='show[{$row['id']}]' value='Show'>",
                 "<br />",
                 "<img src='{$row['filename']}' alt='{$row['name']}' />",
                 "<br />";                         
          }
          ?>
          </form>

And here is the php that is executed when the hide button is pressed.

<?php
        if(isset($_POST['hide'])){
           $chk = (array) $_POST['hide'];
           $p = implode(',',array_keys($chk)); 
           echo $p;
           $t = 'SELECT * FROM headerrotatorimage WHERE id IN ($p)';
           echo $t;
           $s = 'UPDATE headerrotatorimage SET status = 2 WHERE id IN ($p)';
           echo $s;
        }
        ?>

Can anyone point out the problem??

Thanks

Where is your database connection?

Oops! I just added it, but its still the same!

<?php
        include '../inc/connect.php';
        if(isset($_POST['hide'])){
           $chk = (array) $_POST['hide'];
           $p = implode(',',array_keys($chk)); 
           echo $p;
           $t = 'SELECT * FROM headerrotatorimage WHERE id IN ($p)';
           echo $t;
           $s = 'UPDATE headerrotatorimage SET status = 2 WHERE id IN ($p)';
           echo $s;
        }
        ?>

On each click of a button the form gets submitted with only one value. You'd be better off putting checkboxes next to each image (and only one submit button) and then check the array of checked ckeckboxes to produce the IN condition. Just an idea.

I took your advice broj1 and used it with check button for 'show' 'hide' and 'remove'.

Thanks for that.............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.