Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts

    CGI need both $inputs to match, how to code it?

    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.

    Code:
    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'}";

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by awayne96 View Post
    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.

    Code:
    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:

    Code:
    select firstname, login from departures where departures_states = ? and departures_state_region = ?
    best regards

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I actually did part of that after I posted before and was going to just update that... Here is what I have now:

    Code:
    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:

    Code:
    $profiles_sth->execute($input{'state1'} & {'state2'}) or die $DBI::errstr;

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by awayne96 View Post
    I actually did part of that after I posted before and was going to just update that... Here is what I have now:

    Code:
    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:

    Code:
    $profiles_sth->execute($input{'state1'} & {'state2'}) or die $DBI::errstr;
    try:
    Code:
    $profiles_sth->execute($input{'state1'}, $input{'state2'}) or die $DBI::errstr;
    best regards

  • Users who have thanked oesxyl for this post:

    awayne96 (12-05-2009)

  • #5
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    try:
    Code:
    $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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •