Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] perl/cgi and hyperlinks

Expand Messages
  • franky_claeys@yahoo.com
    This is my enteire cgi-script: #!/usr/bin/perl -w use CGI; use DBI; use diagnostics; use Data::Dumper; read(STDIN,$buffer,$ENV{ CONTENT_LENGTH });
    Message 1 of 8 , Jun 3, 2001
    • 0 Attachment
      This is my enteire cgi-script:

      #!/usr/bin/perl -w

      use CGI;
      use DBI;
      use diagnostics;
      use Data::Dumper;


      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;
      $ticker{$name}=$value;
      }

      $dbh=DBI->connect('dbi:mysql:test', 'root', 'anneleen');


      $company=&find_company($ticker{'tick'});

      if ($company eq "notfound")
      {
      print "Content-Type:text/html\n\n";
      print "<html><head></head></html>";
      print "<body><p>help</p></body>";
      }
      else
      {
      &do_for_company($company);
      }


      ###################
      #
      # first subroutine
      #
      ###################

      sub find_company

      {
      $ticker{'tick'}=shift;

      $findcompsql="select comp from ticklist where sym=\"$ticker
      {'tick'}\"";

      $sth2=$dbh->prepare($findcompsql);

      $sth2->execute;

      if
      (@comp_res=$sth2->fetchrow_array)
      {
      $company=$comp_res[0];
      }
      else
      {
      $sth2->finish ();
      return "notfound";
      }
      $sth2->finish ();
      return $company;
      }

      ######################
      #
      # second subroutine
      #
      #####################


      sub do_for_company
      {
      $comp=shift;
      $sql="SELECT max(date) FROM $comp";

      $sth=$dbh->prepare($sql);
      $sth->execute;
      $date= ($sth->fetchrow_array ())[0];
      $sth->finish ();

      $sql2="SELECT * from $comp WHERE date = '$date'";
      $sth=$dbh->prepare($sql2);
      $sth->execute ();
      if (@rows=$sth->fetchrow_array)
      {
      $sym=$rows[0];
      $cname=$rows[1];
      $datum=$rows[2];
      $open=$rows[3];
      $close=$rows[4];
      $high=$rows[5];
      $low=$rows[6];
      $vol=$rows[7];
      $verand=$rows[8];
      print<<"END";
      Content-type:text/html\n\n
      <html>
      <head>
      </head>
      <body>

      [snip html code]

      #I need to make a dynamic link using the input from a html-form
      #The name of the html text field is tick
      #the directory in wich the files are is clinegraphs
      #I have find several solutions in cgi manuals but cannot make it work

      <img src="clinegraphs/\"$ticker{'tick'}.gif\"">


      [snip html code]

      </body>
      </html>
      END
      }
      $sth->finish ();
      }
      $dbh->disconnect;













      --- In perl-beginner@y..., Gordon Stewart <gordonistewart_nz@y...>
      wrote:
      >
      > --- Franky Claeys <franky_claeys@y...> wrote: >
      >
      >
      > Hi all,
      > >
      > > This may be a little bit of a easy problem but I'm
      > > not
      > > finding the solution
      > > (bit of newbie...):
      > >
      > > In a perl/cgi script I would like to construct
      > > something like this rule:
      >
      > > print "<li>name <b><a
      > > href=names/$in{'username'}.htm></a></b> \n";
      > > $in comes from a form-input and in the dir names are
      > > all files with possible
      > > names (equal to the dynamic form-input).
      >
      > If you want to just create the A HREF tags, it should
      > be as follows :-
      >
      > print "<li>name <b><a
      > href=names\/$in{username}.htm><\/a><\/b>\n";
      >
      > you need to back-slash the '/' character
      > - ie \/
      >
      > If you can post the code, so we can see how the $in
      > value is created, - we can help further.
      >
      > Gordon.
      >
      >
      >
      > ____________________________________________________________
      > Do You Yahoo!?
      > Get your free @... address at http://mail.yahoo.co.uk
      > or your free @... address at http://mail.yahoo.ie
    • Charles K. Clarkson
      ... [snip - thanks that was helpful.] ... I m confused: Do you want a link to the image?
      Message 2 of 8 , Jun 3, 2001
      • 0 Attachment
        <franky_claeys@...>

        : This is my enteire cgi-script:

        [snip - thanks that was helpful.]

        : [snip html code]
        :
        : #I need to make a dynamic link using the input from a
        : #html-form. The name of the html text field is tick
        : #the directory in wich the files are is clinegraphs
        : #I have find several solutions in cgi manuals but
        : #cannot make it work
        :

        I'm confused:

        Do you want a link to the image?

        <li>
        <a href="clinegraphs/$ticker{tick}.gif">
        <b>$ticker{tick}</b>
        </a>
        </li>

        Or do you want the image as a link?

        <li>
        <a href="path to some link">
        <img src="clinegraphs/$ticker{tick}.gif">
        </a>
        </li>


        : <img src="clinegraphs/\"$ticker{'tick'}.gif\"">
        :

        HTH,
        Charles K. Clarkson


        If you try to fail, and succeed, which have you done?
      • Greg
        ... work ... Try this: $href= clinegraphs/$ticker{ tick } ; print Lets Go n ; print
        Message 3 of 8 , Jun 4, 2001
        • 0 Attachment
          --- In perl-beginner@y..., franky_claeys@y... wrote:

          > [snip html code]
          >
          > #I need to make a dynamic link using the input from a html-form
          > #The name of the html text field is tick
          > #the directory in wich the files are is clinegraphs
          > #I have find several solutions in cgi manuals but cannot make it
          work
          >
          > <img src="clinegraphs/\"$ticker{'tick'}.gif\"">
          >
          >
          > [snip html code]

          Try this:

          $href="clinegraphs/$ticker{'tick'}";
          print "<html><head><title>Lets Go</title></head><body>\n";
          print "<a href=\"$href.html\"><img src=\"$href.gif\"></a>\n";
          print "</body></html>\n";

          Greg Smith
          webmaster
          www.bmw-club.org.uk
        Your message has been successfully submitted and would be delivered to recipients shortly.