Re: Check Boxes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If one of the checkboxes is NOT checked, then your query will break as
ift will look something like this:

SELECT xxx,,yyy FROM form;

Name your checkboxes like so: ch[]

<input type="checkbox" name="ch[]" value="Enter_Date"/>

Then you can loop through the checkbox array and run your query that way

$chkboxes = $_POST['ch'];
$sql = 'SELECT ';
foreach($chkboxes as $k => $v)
{
	$sql .= $v;
	if($k < (sizeof($chkboxes) - 1))
	{
		$sql .= ', ';
	}
}
$sql .= ' FROM form';


On Wed, 18 Aug 2004 15:01:01 +0530, balwantsingh
<balwantsingh@xxxxxxxxxxxxx> wrote:
> 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";
> $result=@mysql_query ($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: John Holmes [mailto:holmes072000@xxxxxxxxxxx]
> Sent: Wednesday, August 18, 2004 5:43 PM
> To: balwantsingh@xxxxxxxxxxxxx
> Cc: php-db@xxxxxxxxxxxxx
> Subject: Re:  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"
> 
> How about showing us some code.... kind of hard to help without that...
> 
> --
> 
> ---John Holmes...
> 
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
> 
> php|architect: The Magazine for PHP Professionals â www.phparch.com
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
randy sesser@xxxxxxxxx

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux