in reply to Re: passing variables to a sub
in thread passing variables to a sub

nice. thanks for all of that.

it was late (err early), so i missed chromatic et al's suggestion that if didn't reassign $_. however, the if was getting unwieldy and just didn't look good assigning the param to the scalar so i didn't want to do it like that. in the end, i did this:

if ( $cgi->param ) { $sortby = defined ( $cgi->param( 'sortby' ) ) ? $cgi->param( 'sortby' ) : "name"; $ascdesc = defined ( $cgi->param( 'ascdesc' ) ) ? $cgi->param( 'ascdesc' ) : "desc"; $letter = defined ( $cgi->param( 'letter' ) ) ? $cgi->param( 'ascdesc' ) : " "; ownertbl( $sortby, $ascdesc, $letter );

which works fairly well but always ends up true (i think) this is because i am defining my cgi vars in all requests to keep my state (so that if one thing changes everything else doesn't go away). maybe i'll try and test  $($cgi->param( 'whatever' )) > 0 and see if i can make this work.

my other issue is the sql paren is doubling up per:

[Sat Oct 16 11:04:23 2010] [error] [client 192.168.15.177] DBD::mysql: +:st execute failed: You have an error in your SQL syntax; check the m +anual that corresponds to your MySQL server version for the right syn +tax to use near 'WHERE name LIKE '%'' at line 3 at /var/www/cgi-bin/o +wnertbl.pl line 76., referer: http://192.168.15.222/cgi-bin/ownertbl. +pl [Sat Oct 16 11:04:23 2010] [error] [client 192.168.15.177] DBD::mysql: +:st fetchrow_hashref failed: fetch() without execute() at /var/www/cg +i-bin/ownertbl.pl line 79., referer: http://192.168.15.222/cgi-bin/ow +nertbl.pl [Sat Oct 16 11:04:23 2010] [error] [client 192.168.15.177] base = http +://192.168.15.222/cgi-bin/ownertbl.pl, sort = ORDER BY name, sortby = + name, ascdesc = , letter = WHERE name LIKE '%', referer: http://192. +168.15.222/cgi-bin/ownertbl.pl

but, i haven't really studied your sql suggestions so i'm hoping with a closer look at that i'll be able to fix this too.

thanks for the help

Replies are listed 'Best First'.
Re^3: passing variables to a sub
by graff (Chancellor) on Oct 17, 2010 at 00:49 UTC
    Whenever I see this in the httpd error log:
    You have an error in your SQL syntax; check the manual ... for the right syntax to use near '...'
    I know that the actual mistake usually precedes the part that is being quoted in the error message. So the next thing I do is to add something like this to the program, just before the $dbh->prepare( $sql ) call:
    warn "$0: preparing sql: $sql\n";
    Then I watch the error log to see what the whole sql statement text looks like, and this makes it easier to spot where I went wrong in putting it together.

    In your case (based on other code you've posted earlier in this thread), I'm guessing that you have your "ORDER BY ..." and "WHERE ..." clauses in the wrong order ("WHERE ..." is supposed to come before "ORDER BY ...").