Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with checkbox form data & sql

Status
Not open for further replies.

rgpmedia

Programmer
Mar 6, 2005
7
US
hello I am at my wits end. I am having trouble processing multi-select lists and checkboxes then sendind the form data to my sql database. it creates/updates the record fine. however it never post all the data from the checked boxes, uses only one. I am using perl because I dont know any php. But the process should be the same. Here is a sample what I have so far. I only included the important parts of the code for each. but no matter how many boxes are checked on one value is returned. I would greated appreciate any solutions

Mike

[html form]
<form action="quest_done.cgi" method="post">
1. What location do you fantasize about for a scene?</B>
</font><br>
<input type=checkbox name=QUESTIONlocation_encounter value=01 > A dungeon<br>
<input type=checkbox name=QUESTIONlocation_encounter value=02 > An old castle<br>
<input type=checkbox name=QUESTIONlocation_encounter value=03 > The beach<br>
<input type=checkbox name=QUESTIONlocation_encounter value=04 > A moving vehicle (i.e. car)<br>
<input type=checkbox name=QUESTIONlocation_encounter value=05 > My bed<br>
<input type=checkbox name=QUESTIONlocation_encounter value=06 > An airplane<br>
<input type=checkbox name=QUESTIONlocation_encounter value=07 > A dark back alley<br>
<input type=checkbox name=QUESTIONlocation_encounter value=08 > A movie theatre<br>
<input type=checkbox name=QUESTIONlocation_encounter value=09 > A funeral home<br>
<input type=checkbox name=QUESTIONlocation_encounter value=10 > A medieval torture chamber<br>
<input type=checkbox name=QUESTIONlocation_encounter value=11 > Under a waterfall<br>
<input type=checkbox name=QUESTIONlocation_encounter value=12 > My desk at work<br>
<input type=checkbox name=QUESTIONlocation_encounter value=13 > Elevator<br>
<input type=checkbox name=QUESTIONlocation_encounter value=14 > A swimming pool or hot tub<br>
<input type=checkbox name=QUESTIONlocation_encounter value=15 > A store dressing room<br>
<input type=checkbox name=QUESTIONlocation_encounter value=16 > The mnamedle of Central Park<br>
<input type=checkbox name=QUESTIONlocation_encounter value=17 > A Church<br>
<input type=checkbox name=QUESTIONlocation_encounter value=18 > Different time period (past or present)<br>
<input type=submit name=submit value=answer>
</form>

[quest_done.cgi]

&form_parse;
$location = $FORM{'QUESTIONlocation_encounter'};
#
use DBI;
$dbh = DBI->connect("dbi:mysql:$mysqldatabase","$mysqlusername","$mysqlpassword") || die("Couldn't connect to database!\n");
print "Content-Type: text/html\n\n";
#
&savedata;
&printconfirmation;
$dbh->disconnect;
#
sub savedata {
$query = "REPLACE INTO Question values('$locations')";
$dbh->do($query);
}
#
sub form_parse {
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair(@pairs){
($name,$value)=split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->/ /g;
$value =~ tr/\\|[|]|<|!|"|$|{|}|*|#|'|>|||;|%/ /;
$FORM{$name} = $value;
}
}
#
 
as far as i know (swampboogie will correct me for sure if i'm wrong) there is no such statement in ansi sql as REPLACE INTO

in any case, your question is probably not a database question at all, rather a problem with your front-end script

try the Perl forum

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts March 6 2005)
 
excuse me yes there is. REPLACE is use in place of INSERT in instances where a record exists already containing the key which is "username". Why dont you stick to the problem I asked. The REPLACE isn not the problem, parsing all the checked boxes is the problem...
 
please do not be so rude

i said there is no such thing as REPLACE in ansi sql

there's a REPLACE command in mysql, but this isn't the mysql forum

this is the ansi sql forum

and if parsing the checkboxes is really the problem, you most definitely are in the wrong forum


rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts March 6 2005)
 
I said no offense and I am sorry I didnt know there was a difference in sql.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top