c cgi script display results below html form


B

bpascal123

Hi,

I'm implementing a simple c script from a book as a server cgi-bin executable.

I would like the result of the script to be displayed in the same web page from which it is called

Example:

The html page that hosts the form and calls simplest.cgi

<FORM ACTION = "cgi-bin/simplest.cgi" METHOD="POST">
<p><i>Search info from this form using cgi script</i></p>
<br />
<p>Title <INPUT TYPE="TEXT" SIZE=20 NAME="titre"></p>
<br />
<p><INPUT TYPE="SUBMIT" VALUE=" Search ">
</FORM>


simplest.cgi looks like this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXL 132

int main(int arg, char *argv[]){

/* Phase 1 variables */
int lg ;
char ligne[MAXL];

printf ("Content-type: text/html\n\n");
printf ("<HEAD><TITLE>Résultat de la recherche</TITLE>");
printf ("</HEAD><BODY bgcolor=white>");
printf ("<H1><CENTER>Résultat de la recherche</CENTER></H1>");

/* Phase 1 Extraction des paramètres */

lg = atoi (getenv("CONTENT_LENGTH"));
fgets(ligne, lg+1, stdin);
printf("<B>Paramètres :</B> %s<P>\n", ligne);
return 0;
}

Can I include the printf function to show its argument directly on the htmlpage above?

Thanks
Pascal
 
Ad

Advertisements

B

bpascal123

What i think of but i'm not sure of how efficient it is, it's to insert a tag comment in the html below the form, from the cgi c script, open that html file, look for the comment text and display results there.
 
I

Ian Collins

bpascal123 said:
Hi,

I'm implementing a simple c script from a book as a server cgi-bin executable.

I would like the result of the script to be displayed in the same web page from which it is called

Example:

The html page that hosts the form and calls simplest.cgi

<FORM ACTION = "cgi-bin/simplest.cgi" METHOD="POST">
<p><i>Search info from this form using cgi script</i></p>
<br />
<p>Title <INPUT TYPE="TEXT" SIZE=20 NAME="titre"></p>
<br />
<p><INPUT TYPE="SUBMIT" VALUE=" Search ">
</FORM>


simplest.cgi looks like this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXL 132

int main(int arg, char *argv[]){

/* Phase 1 variables */
int lg ;
char ligne[MAXL];

printf ("Content-type: text/html\n\n");
printf ("<HEAD><TITLE>Résultat de la recherche</TITLE>");
printf ("</HEAD><BODY bgcolor=white>");
printf ("<H1><CENTER>Résultat de la recherche</CENTER></H1>");

/* Phase 1 Extraction des paramètres */

lg = atoi (getenv("CONTENT_LENGTH"));
fgets(ligne, lg+1, stdin);
printf("<B>Paramètres :</B> %s<P>\n", ligne);
return 0;
}

Can I include the printf function to show its argument directly on the html page above?

Yes, but not closing the main HTML tags will quite likely give your
browser the shits.
 
Ad

Advertisements

J

Joachim Schmitz

Ian said:
bpascal123 said:
Hi,

I'm implementing a simple c script from a book as a server cgi-bin
executable. I would like the result of the script to be displayed in the
same
web page from which it is called Example:

The html page that hosts the form and calls simplest.cgi

<FORM ACTION = "cgi-bin/simplest.cgi" METHOD="POST">
<p><i>Search info from this form using cgi script</i></p>
<br />
<p>Title <INPUT TYPE="TEXT" SIZE=20 NAME="titre"></p>
<br />
<p><INPUT TYPE="SUBMIT" VALUE=" Search ">
</FORM>


simplest.cgi looks like this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXL 132

int main(int arg, char *argv[]){

/* Phase 1 variables */
int lg ;
char ligne[MAXL];

printf ("Content-type: text/html\n\n");
printf ("<HEAD><TITLE>Résultat de la recherche</TITLE>");
printf ("</HEAD><BODY bgcolor=white>");
printf ("<H1><CENTER>Résultat de la recherche</CENTER></H1>");

/* Phase 1 Extraction des paramètres */

lg = atoi (getenv("CONTENT_LENGTH"));
fgets(ligne, lg+1, stdin);
printf("<B>Paramètres :</B> %s<P>\n", ligne);
return 0;
}

Can I include the printf function to show its argument directly on
the html page above?

Yes, but not closing the main HTML tags will quite likely give your
browser the shits.

I guess you meant "closing the BODY tag", as he didn't even open an HTML tag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top