pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
insert value of form - checkboxes
2+ messages / 2 participants
[nested] [flat]

* insert value of form - checkboxes
@ 2000-11-09 08:05  Astrid Hexsel <ahexse01@postoffice.csu.edu.au>
  0 siblings, 1 reply; 2+ messages in thread

From: Astrid Hexsel @ 2000-11-09 08:05 UTC (permalink / raw)
  To: pgsql-sql

Hello all,

 I have a form which has got checkboxes and I am having problems  to have their
values stored in different rows of a table.


What I have done is: 

# colour_id is the name of my checkboxes in the input tag
<input type=checkbox name=colour_id value=200>
<input type=checkbox name=colour_id value=201> 
etc ...

# I put all the values into the array and split them

$colour = $formdata{'colour_id'};
@colours = split (/,/, $colour);

#then I want to insert then into a table (called cart)in the row called colour_id.
If I have more than one value they have to be in different rows.

# my code:

  foreach $colour(@colours)
    {
       $qry = INSERT INTO cart VALUES 
              ('$session_id', '$range_id', '$colour')
    }

And what happens is that I am only getting just
one value now inserted in the row. If for example I checked 3 boxes I will get
only the last
one.

The foreach loop works fine out of the query.

Thanks a lot for any help.

Astrid






 


   





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: insert value of form - checkboxes
@ 2000-11-09 08:41  Antti Linno <alligator@all.ee>
  parent: Astrid Hexsel <ahexse01@postoffice.csu.edu.au>
  0 siblings, 0 replies; 2+ messages in thread

From: Antti Linno @ 2000-11-09 08:41 UTC (permalink / raw)
  To: Astrid Hexsel <ahexse01@postoffice.csu.edu.au>; +Cc: pgsql-sql



On Thu, 9 Nov 2000, Astrid Hexsel wrote:

> Hello all,
> 
>  I have a form which has got checkboxes and I am having problems  to have their
> values stored in different rows of a table.
> 
> 
> What I have done is: 
> 
> # colour_id is the name of my checkboxes in the input tag
> <input type=checkbox name=colour_id value=200>
> <input type=checkbox name=colour_id value=201> 
> etc ...
> 
> # I put all the values into the array and split them
> 
> $colour = $formdata{'colour_id'};
> @colours = split (/,/, $colour);

Try to print the array out, to check whether all values are there.

> 
> #then I want to insert then into a table (called cart)in the row called colour_id.
> If I have more than one value they have to be in different rows.
> 
> # my code:
> 
>   foreach $colour(@colours)
>     {
>        $qry = INSERT INTO cart VALUES 
>               ('$session_id', '$range_id', '$colour')
>     }
> 

Try to specify what are you inserting, and use double quotes:

foreach $colour (@colours) {

	$qry = qq{ 
		INSERT INTO cart (session_id,range_id,colour) VALUES
			('$session_id','$range_id','$colour')
		};

	$dbh->do(qq{ $qry });# how about this?

}


Btw, try print out in the loop to see, if you are getting right inserts.

> And what happens is that I am only getting just
> one value now inserted in the row. If for example I checked 3 boxes I will get
> only the last
> one.
> 
> The foreach loop works fine out of the query.
> 
> Thanks a lot for any help.

Advice, don't take my CGI as pure gold. I use Embperl, and so my cgi may
be not so error-free :)

Greetings,
	Antti





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2000-11-09 08:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-11-09 08:05 insert value of form - checkboxes Astrid Hexsel <ahexse01@postoffice.csu.edu.au>
2000-11-09 08:41 ` Antti Linno <alligator@all.ee>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox