#include #include #include "cgi-lib.h" #include /* * Purpose: To read names from Postgresql database and print them. It is a CGI. * It requires cgi-lib.h and cgi-lib.c functions. */ char mode[5]; FieldArray *fa; int main() { ReadParse(&fa); mode = (char *)GetValue(&fa, "mode"); if(strcasecmp(&mode, "view") == 0) { displaylist(); } else if(strcasecmp(&mode, "add") == 0) { // addentry(); } } int displaylist() { int totalnames = 1; PGconn* conn; PGresult* res; struct fullnames { char first[50]; char last[50]; }; /* Connect to database */ conn = PQsetdb("localhost",NULL,NULL,NULL,"names"); if(PQstatus(&conn) == CONNECTION_BAD) { printf("%s",PQerrormessage(conn)); exit(1); } res = PQexec(conn, "SELECT * from namelist;"); if(PQresultStatus(&res) == PGRES_TUPLES_OK) { int i; int j=0; totalnames = (int *)PQntuples(res); struct fullnames fullnameslist[50]; for(i=0; i%s %s
",fullnameslist[1].first, fullnameslist[1].last); } HtmlBot(); }