0

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

3
Contributors
4
Replies
31
Views
4 Years
Discussion Span
Last Post by GlenRogers
0

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;
        }
        ?>
0

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.

0

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.