Обсуждение: heeeeeeeeeeeeelp meeeeeeeeeeee

Поиск
Список
Период
Сортировка

heeeeeeeeeeeeelp meeeeeeeeeeee

От
"rony khoury"
Дата:
Ok ,

Sorry guys , I'm so confused , but your answers helped me set things
more straight .

First I have redhat linux 5.0 running on my system , with it comes
postgresql I got these
to run fine on my system using psql as the interface .

I want to be able to access this database from html browsers , because I
have mutliple
platforms I need to work with , and I do not want to develop different
users interfaces .
taking into consideration that I do not want to worry now about www or
different platform
I will be satisfied If I can run the system on linux and localy without
going on the interenet .

Now I tried a two steps procedure to do so , first is to conect from C
to postgresql , and latter to
use C modules as cgi called from browsers .


I will take the problems I got one at a time ,
============ 1 ================
fist I need to conect it to c language , I tried the sample code that
came with postgresql
in my program with only the function exit_nicely , when I compile I get
the following
message

        tmp/cca006421.o: In function `exit nicely'
        tmp/cca006421.o(.text+0x8): undefined reference to `PQfinish'

how can I solve that ? should I send some parameters to the c compiler ?



============== 2 =================
second , I read many tutorials about cgi , and still could not find how
to pass a form from html
to c language after a submit , i know it is not adequate to ask here ,
but I'm verry verry verry low
on time . please reffer me on how to do that .

thanks a million ,
Rony .


Re: [INTERFACES] heeeeeeeeeeeeelp meeeeeeeeeeee

От
Vince Vielhaber
Дата:
On Mon, 29 Jun 1998, rony khoury wrote:

> I will take the problems I got one at a time ,
> ============ 1 ================
> fist I need to conect it to c language , I tried the sample code that
> came with postgresql
> in my program with only the function exit_nicely , when I compile I get
> the following
> message
>
>         tmp/cca006421.o: In function `exit nicely'
>         tmp/cca006421.o(.text+0x8): undefined reference to `PQfinish'
>
> how can I solve that ? should I send some parameters to the c compiler ?


Did you link the postgresql library?  -llibpq

> ============== 2 =================
> second , I read many tutorials about cgi , and still could not find how
> to pass a form from html
> to c language after a submit , i know it is not adequate to ask here ,
> but I'm verry verry verry low
> on time . please reffer me on how to do that .

Since you're running linux, you're probably running apache.  Look in the
apache source dirs and find the sample program that uses util.c.  The
easiest thing for you to do is to use util.c as is and use the few lines
in the program that uses it to parse the cgi.  They'll look something like
this:

    cl = atoi(getenv("CONTENT_LENGTH"));

    for(x=0;cl && (!feof(stdin));x++) {
        m=x;
        entries[x].val = fmakeword(stdin,'&',&cl);
        plustospace(entries[x].val);
        unescape_url(entries[x].val);
        entries[x].name = makeword(entries[x].val,'=');
    }


The resultant items from the form will be in the entries structure.  Name
will be the tag's name and val will be it's value.

Vince.
--
==========================================================================
Vince Vielhaber -- KA8CSH   email: vev@michvhf.com   flame-mail: /dev/null
       # include <std/disclaimers.h>                   TEAM-OS2
   Online Searchable Campground Listings    http://www.camping-usa.com
       "There is no outfit less entitled to lecture me about bloat
               than the federal government"  -- Tony Snow
==========================================================================



Re: [INTERFACES] heeeeeeeeeeeeelp meeeeeeeeeeee

От
Constantin Teodorescu
Дата:
rony khoury wrote:
>
> First I have redhat linux 5.0 running on my system , with it comes
> postgresql I got these
> to run fine on my system using psql as the interface .

I would recommend you to install RedHat 5.1 and updates because it has a
lot of things improved, even PostgreSQL libraries preinstalled.

> Now I tried a two steps procedure to do so , first is to conect from C
> to postgresql , and latter to
> use C modules as cgi called from browsers .

With PHP you will mix : HTML generator, database connection and form
processing.
It's just simple. Look over my examples that I have sent to you and you
will see how.
In PHP, you will find the form variables that you have defined a
previous HTML form as local variables.
Just use them and don't even think how they have been passed.

You might get some problems trying to compile PHP with PostgreSQL
support and apache with PHP module, but reading their README's will be
just fine. Just follow them. If you have some problems, just ask.

Apache 1.3.0  + PHP 3.0  would be a good choice.
Also ,Perl cgi's would be fine.

I am giving you here an example how to get form variables in Perl and
how to connect to PostgreSQL database.

#!/usr/bin/perl

use Pg;

   $datele = <STDIN>;
   @pairs = split(/&/, $datele);
   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
      # restore blank
      $value =~ tr/+/ /;
      # restore special char
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      # store them into associative array %VAR
      chomp $value; $value =~ s/\r//;
      $VAR{$name} = $value ;
   }

#  preluam cimpurile transmise in variabile
   $nrfact   = $VAR{'nrfact'};
   $client   = $VAR{'client'};
   $valoare  = $VAR{'valoare'};
   $datafact = $VAR{'datafact'};
   $continut = $VAR{'continut'};
   $continut =~ s/'/\\'/g;

   ($zi,$luna,$an) = split(/\./,$datafact);
   $datafact = $luna.'-'.$zi.'-'.$an;

# Acest rind este obligatoriu pentru inceput de HTML raspuns
print "Content-type:text/html\n\n";

print <<EOM;
<HTML>
<HEAD>
<TITLE>Emitere factura</TITLE>
</HEAD>
<BODY>
<H1>S-a emis urmatoarea factura</H1>
Factura cu numarul : $nrfact <br>
Data emiterii : $datafact <br>
Catre clientul : $client <br>
Valoarea facturii : $valoare <br><br>
EOM

$con=PQsetdb('',5432,'','','doc');

$res=PQexec($con,"select * from factemise where nrfact='$nrfact'");
$errmsg=PQerrorMessage($con);
if ($errmsg ne '') {
   print "<B> Eroare select verificare dubluri<br>",$errmsg;
   print "</body></html>\n";
   PQclear($res); PQfinish($con);
   exit 1;
}
if (PQntuples($res) > 0) {
   print "<b>Eroare : Mai exista o factura cu numarul $nrfact<b>";
   print "</body></html>\n";
   PQclear($res); PQfinish($con);
   exit 1;
}
PQclear($res);

$sqlcmd="insert into factemise (nrfact,datafact,client,valoare,
continut) values
('$nrfact','$datafact','$client','$valoare','$continut')";
#print $sqlcmd;
$res=PQexec($con,$sqlcmd);
$errmsg = PQerrorMessage($con);
if ( $errmsg ne '' ) {
     print '<font color="#FF0000">';
     print "<b>EROARE INSERT : MESAJ = ",$errmsg,"</b></font><br>";
} else {
     print 'Inregistrarea a fost efectuata !';
}

print "</body></html>\n";

PQclear($res);
PQfinish($con);


--
Constantin Teodorescu
director FLEX Consulting Braila, ROMANIA