Jump to content

updating multiple rows through Checkboxes


jaminxz

Recommended Posts

Hi everyone,

 

i'm trying to create a page that displays multiple records and a checkbox for each row. When the submit buton is clicked, every record that has its checkbox clicked should have its status fields updated to '0'. I have been following this tutorial http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database/page4 (and trying to tailor it slightly to my needs) but with no joy.

 

My problem is that the value of the checkbox (whcih should be ID) is not getting passed through for some reason - i have been using var_dump to tell this. I'm sure its a rookie mistake i'm making but i've spent hours on this and cant get it to work. Please can comeone cast their eye over it and hopefully help me out? many thanks in advance,

Jaminxz.

 

The checkbox code:

 

<td colspan="2" align="left"><span><input type="checkbox" name="Update[]" value="<?php $row_query4['ID']; ?>" /></span></td>

 

/*note $row_query4['ID'] is definitiely pulling through the id

The main code block:

 

$updated = FALSE;

 

//If IS_PostBack then database is to be updated

if(isset($_POST['Update'])){

 

    $Update = $_POST['Update']; 

 

//make sure every ID in the array is an integer to avoid SQL injection!

    array_map('intval',$Update);

 

  $Update = implode(',',$Update); 

 

  mysql_query("UPDATE Ad_item SET STATUS=0 WHERE ID IN ($Update)") or      trigger_error(mysql_error(),E_USER_ERROR);

 

  $updated=TRUE; 

}

 

Output from var_dump-------------

 

array

  0 => string '' (length=0)

  1 => string '' (length=0)

  2 => string '' (length=0)

 

 

/* It knows how many checkboxes have been checked, but just not the value?? */

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.