in reply to CGI executing a SQL statement

"just don't work" isn't going to help us help you. You've told us why your doing things this way and what code you used. You haven't told us what exactly is wrong though (error messages for example). Start out by reading How (Not) To Ask A Question then come back and give us more information. I suspect that you already have all the information you need to figure this out for yourself though.

Replies are listed 'Best First'.
Re^2: CGI executing a SQL statement
by kjg (Sexton) on Apr 18, 2006 at 15:11 UTC
    OK. If I try and put this code:
    $db = new Win32::ODBC("$DSN"), if ($dept ='CA'){ if (!($db=new Win32::ODBC($DSN))) { print "Error connecting to Database\n"; print "Error: " . Win32::ODBC::Error() . "\n"; } $SqlStatement = "SELECT * FROM Pipeline WHERE Publish<='$tod +ay' AND Expiry>='$today' AND CA='Must Read'"; if ($db->Sql($SqlStatement)) { print "SQL failed.\n <br>$SqlStatement\n"; print "Error: " . $db->Error() . "\n"; } else { while($db->FetchRow()) { %Data = $db->DataHash(); print "<li><a href=\"http://wwwybs/ybsone/Pipeline/master/ +$folderday/$Data{'Ref'}\" target=\"main\"><strong><font face=\"Arial\ +">$Data{'Title'}</a></font>Theme: $Data{'Theme'}</li>"; } } $db->Close(); }
    In after this statement in the CGI that I described above:
    $cgi->p("$dept was received."),
    I just get compilation errors and random messages about syntax errors. Why?

      "I just get compilation errors and random messages about syntax errors. Why?"

      They aren't random at all. Read them. They will tell you where the problem lies.

      You probably want to add code after a statement instead of in the middle as you said you did: "If I try and put this code... In after this statement in the CGI that I described above... I just get compilation errors and random messages about syntax errors."

      You probably also want to terminate your statements with semicolons instead of not terminating them at all or doing so with commas.

      $today = 'somedate'; # was: $today = 'somedate' # snip 8< $db = new Win32::ODBC("$DSN"); # was: $db = new Win32::ODBC("$DSN"),

      updated a few times within the first several minutes after posting since i seemed to miss a few things.

      Your "database" code has all the looks of a badly executed "cut-and-paste" job. It might have worked in another script, but it is obviously broken in this script.

      Unless you have predeclared (using "my") all variables in this script somewhere else, Perl will keep complaining since you have asked it to do so by using "use strict;".

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Hi, it's me again, Anonymonk. I gave you this CGI program a couple of days ago: Re: Drop down and display.

      You just said:

      I just get compilation errors and random messages about syntax errors.

      These errors are not random! They were generated for a reason!

      Why?

      You are supposed to read them up in your favourite Perl manual and act accordingly. We can't help as we don't know which one you got. If you haven't bought a book yet, perhaps perldiag helps.

      If you can't make heads or tails out of them, come back here with the exact wording ('cause The Error Message Is God™) and say so; but don't be so terribly lazy, mon.