Jump to content

Checkbox blues


ksmatthews

Recommended Posts

HI there,

 

I have the following checkboxes where I am using an array called check[] ...

 

<input name = "check[]" type = "checkbox" value = 'somevalue1' />

<input name = "check[]" type = "checkbox" value = 'somevalue2' />

<input name = "check[]" type = "checkbox" value = 'somevalue3' />

 

When selected by the user, I wish to delete the selected records using this code ...

 

// capture checkbox data

$data = $_POST['check'];

 

// start delete loop

foreach ($data as $key => $value )

  {

    // create SQL string

    $SQL = 'DELETE FROM ' . $table . ' WHERE name = "' . $value .'"';

 

    // run SQL query

    code goes here

  }

 

This code works fine ! BUt the javascipt functionality that references it does not work !

 

What I would like to know is how I can do the same thing but AVOID using the check[] array, by using checkboxes like this ...

 

<input name = "check" type = "checkbox" value = 'somevalue1' />

<input name = "check" type = "checkbox" value = 'somevalue2' />

<input name = "check" type = "checkbox" value = 'somevalue3' />

 

Has anyone got any good references for dealing with checkboxes in php ?

 

thanks,

 

Steven Matthews

 

 

Link to comment
https://forums.phpfreaks.com/topic/70862-checkbox-blues/
Share on other sites

ok i used a for loop e.g.

 

for($i=0;$i<10;$i++)

{

  echo "<input type=\"checkbox\" name=\"red[$i]\">

}

 

then to process:

 

for($j=0;$j<10;$j++)

{

  $valueofcheckbox = $red[$i];

  if($valueofcheckbox=="on")

  {

      echo "$j is ON";

  }

  else

  {

      echo "$j is OFF";

  }

}

 

i'm sure you can figure out how to put this in a while loop if you're using a mysql recordset.

Link to comment
https://forums.phpfreaks.com/topic/70862-checkbox-blues/#findComment-356246
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.