0

I'm trying to make a bulk action. I have checkboxes,

<input type="checkbox" name="check_id[]" value="1">
<input type="checkbox" name="check_id[]" value="2">
<input type="checkbox" name="check_id[]" value="3">

I wanted to select values from mysql table for each selected checkboxes then use my function to delete data based on the fetched values. I tried,

for( $i = 0; $i < count( $_POST['check_id'] ); $i++ ) {
  $manufacturers_id = prepare_input($_POST['check_id'][$i]);
  $manufacturer_query = mysql_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
  $manufacturer = mysql_fetch_array($manufacturer_query);

  delete_image(DIR_IMAGES . $manufacturer['manufacturers_image']);
}

The problem is that, there is no fetched mysql values based on $_POST['check_id'] even though im sure that i have manufacturers_image where is manufacturers_id is either 1,2 or 3.

Is there a correct way to accomplish this?

6
  • try foreach($_POST['check_id'] as $i=>$value) Commented Aug 18, 2012 at 11:58
  • 1
    What does prepare_input function do? try echo $_POST['check_id'][$i] before that function to check if you're receiving values Commented Aug 18, 2012 at 12:01
  • @Hamurabi there is receiving values.. like array([0] => 1).. its just mysql_escape_string.. Commented Aug 18, 2012 at 12:30
  • @fluty I tried foreach but its not working either. Commented Aug 18, 2012 at 12:32
  • @Ken then do the following, echo the query to check if it is the right query. ex: echo "select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manufacturers_id ."'"; Commented Aug 18, 2012 at 12:35

2 Answers 2

1

Change this line

$manufacturer = mysql_fetch_array($manufacturer_query);

to

$manufacturer = mysql_fetch_assoc($manufacturer_query);
Sign up to request clarification or add additional context in comments.

Comments

0

It is returning an array ... you use while() or you fetch first image

delete_image(DIR_IMAGES . $manufacturer[0]['manufacturers_image']);

Comments

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.