You got it right, except you're going to have it blow up on you if someone doesn't select something
Try these changes: $a1 = $_POST['ch1']; $a2 = $_POST['ch2']; $a3 = $_POST['ch3']; # Add this bit If (isset($_POST['ch1')) { $collist .= ",$a1"; } If (isset($_POST['ch2')) { if ($collist == "") { $collist = $a2; } else { $collist .= ",$a2"; } }If (isset($_POST['ch3')) { if ($collist == "") { $collist = $a3; } else { $collist .= ",$a3"; } } # Make slight changes here if ($collist <> "") { $query = "SELECT $collist FROM form"; [EMAIL PROTECTED] ($query); } Enter_Date<input type="checkbox" name="ch1" value="Enter_Date"> Opening_Units<input type="checkbox" name="ch2" value="Opening_Units"> Unit_Consumed<input type="checkbox" name="ch3" value="Unit_Consumed"> > -----Original Message----- > From: balwantsingh [mailto:[EMAIL PROTECTED] > Sent: Wednesday, August 18, 2004 5:33 AM > To: [EMAIL PROTECTED] > Subject: [PHP] [PHP-GEN] Check Boxes > > > balwantsingh wrote: > > can somebody advise me > > i want to use checkboxes on my website, i want that if user > selects some > > checkboxes (there will be more than 20 checkboxes), > checkbox's value will > be > > stored in variables and than SELECT query command will be > run using these > > variables through PHP. but my problem is that in SELECT > query command > after > > each column name comma (,) is required and if i use the > same than it is > > displaying "You have an error in your SQL syntax near > 'FROM form' at line > > 1" > > i am using following coding > > $a1 = $_POST['ch1']; > $a2 = $_POST['ch2']; > $a3 = $_POST['ch3']; > > if ($a1 or $a2 or $a3) { > $query = "SELECT $a1, $a2, $a3 FROM form"; > [EMAIL PROTECTED] ($query); > } > Enter_Date<input type="checkbox" name="ch1" value="Enter_Date"> > Opening_Units<input type="checkbox" name="ch2" value="Opening_Units"> > Unit_Consumed<input type="checkbox" name="ch3" value="Unit_Consumed"> > > > > balwant > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php