c cgi script display results below html form

Discussion in 'C Programming' started by bpascal123, Mar 17, 2013.

  1. bpascal123

    bpascal123 Guest

    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, Mar 17, 2013
    #1
    1. Advertising

  2. bpascal123

    bpascal123 Guest

    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.
     
    bpascal123, Mar 17, 2013
    #2
    1. Advertising

  3. bpascal123

    Ian Collins Guest

    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
     
    Ian Collins, Mar 18, 2013
    #3
  4. 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
     
    Joachim Schmitz, Mar 19, 2013
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    175
    Michael Fesser
    Oct 28, 2004
  2. kath
    Replies:
    4
    Views:
    812
    J. Gleixner
    Apr 9, 2007
  3. kwan
    Replies:
    6
    Views:
    309
  4. Mel
    Replies:
    5
    Views:
    145
  5. kiran
    Replies:
    12
    Views:
    1,222
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page