Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   c cgi script display results below html form (http://www.velocityreviews.com/forums/t958742-c-cgi-script-display-results-below-html-form.html)

bpascal123 03-17-2013 04:39 PM

c cgi script display results below html form
 
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

bpascal123 03-17-2013 04:44 PM

Re: c cgi script display results below html form
 
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.

Ian Collins 03-18-2013 07:24 AM

Re: c cgi script display results below html form
 
bpascal123 wrote:
> 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.

--
Ian Collins

Joachim Schmitz 03-19-2013 10:33 AM

Re: c cgi script display results below html form
 
Ian Collins wrote:
> bpascal123 wrote:
>> 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



All times are GMT. The time now is 05:41 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.