Jump to content

processing checkbox form with PHP


poleposters

Recommended Posts

I have a form with several checkbox choices.

 

<input type="checkbox" name="color[]" value="red" >
<label for="red">Red</label>

<input type="checkbox" name="color[]" value="yellow">
<label for="Yellow">Yellow</label>

<input type="checkbox" name="color[]" value="blue" >
<label for="Blue">Blue</label>

And this is how I'm processing the info


<?php

include "mysql_connectratedr.php";
require_once ('config.inc.php'); 
include "admin/var.php";
$kink=$_POST["color"];

$n=count($link);
   
   for($i=0;$i<$n;$i++){
      
$query="INSERT INTO specialties (specialty_id,business_id,specialty) VALUES ('','1','$link[$i].')";
  
$query2=mysql_query($query);}

?>

 

Everything works fine. Except I want to combine this form with some javascript. The problem is that the name of the checkboxes includes square brackets.

 

name="color[]"

 

The presence of the brackets cause the javascript to fail.(I've tried escaping them with no luck). The only solution I see is to remove the square brackets from the checkbox name. However when I do this, the form fails to process correctly.

 

Is there a way to rewrite the form/script without using square brakets in the name?

 

Link to comment
https://forums.phpfreaks.com/topic/124572-processing-checkbox-form-with-php/
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.