awayne96
12-05-2009, 05:12 AM
Below is code in a CGI script that I have. Both state1 & state2 must be matched in the table when it is excuted. I can't seem to figure out how it needs to be coded to work.
What this script is doing is its searching if a user is in state1 and headed to state2 and they must match to get a notification regarding a new posting.
my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_states` = ?" ) or die $DBI::errstr;
my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_state_region` = ?" ) or die $DBI::errstr;
$profiles_sth->execute($input{'state1'} AND ($input{'state2'}) or die $DBI::errstr;
while(my $profiles = $profiles_sth->fetchrow_hashref()){
my $firstname = "$profiles->{'firstname'}";
my $login = "$profiles->{'login'}";
oesxyl
12-05-2009, 06:45 AM
Below is code in a CGI script that I have. Both state1 & state2 must be matched in the table when it is excuted. I can't seem to figure out how it needs to be coded to work.
What this script is doing is its searching if a user is in state1 and headed to state2 and they must match to get a notification regarding a new posting.
my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_states` = ?" ) or die $DBI::errstr;
my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_state_region` = ?" ) or die $DBI::errstr;
$profiles_sth->execute($input{'state1'} AND ($input{'state2'}) or die $DBI::errstr;
while(my $profiles = $profiles_sth->fetchrow_hashref()){
my $firstname = "$profiles->{'firstname'}";
my $login = "$profiles->{'login'}";
why you don't you put both query in a single one and fetch only what you need from the table? something like this:
select firstname, login from departures where departures_states = ? and departures_state_region = ?
best regards
awayne96
12-05-2009, 07:05 AM
I actually did part of that after I posted before and was going to just update that... Here is what I have now:
my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_states` = ? AND `departures_state_region` = ?" ) or die $DBI::errstr;
$profiles_sth->execute($input{'state1'} & {'state2'}) or die $DBI::errstr;
With the above code I get an error:
Software error:
called with 1 bind variables when 2 are needed at /ship_state.cgi line 70.
Line 70 is:
$profiles_sth->execute($input{'state1'} & {'state2'}) or die $DBI::errstr;
oesxyl
12-05-2009, 07:08 AM
I actually did part of that after I posted before and was going to just update that... Here is what I have now:
my $profiles_sth = $dbh->prepare("SELECT * FROM `departures` WHERE `departures_states` = ? AND `departures_state_region` = ?" ) or die $DBI::errstr;
$profiles_sth->execute($input{'state1'} & {'state2'}) or die $DBI::errstr;
With the above code I get an error:
Software error:
called with 1 bind variables when 2 are needed at /ship_state.cgi line 70.
Line 70 is:
$profiles_sth->execute($input{'state1'} & {'state2'}) or die $DBI::errstr;
try:
$profiles_sth->execute($input{'state1'}, $input{'state2'}) or die $DBI::errstr;
best regards
awayne96
12-05-2009, 07:20 AM
try:
$profiles_sth->execute($input{'state1'}, $input{'state2'}) or die $DBI::errstr;
best regards
Thanks, that worked!
I realized that I forgot to change one other thing that was causing it not to work. I wasn't getting that error anymore so I figured it had to be something else.... it was a simple wrong field name. It works perfect now :)
Thanks again for the help.