Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > c cgi script display results below html form

Reply
Thread Tools

c cgi script display results below html form

 
 
bpascal123
Guest
Posts: n/a
 
      03-17-2013
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
 
Reply With Quote
 
 
 
 
bpascal123
Guest
Posts: n/a
 
      03-17-2013
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.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-18-2013
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
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      03-19-2013
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser crashes with below code.What is wrong in below code. kiran Javascript 12 12-07-2011 02:38 PM
Display the answer in HTML code because CGI-SCript could not hide kwan Perl Misc 6 11-26-2007 04:30 PM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
Could someone scan me a picture of the below? (Read Below) starlightvoyager@yahoo.com DVD Video 1 08-28-2006 05:42 AM
How to transfer variables from a .php script to an .html page that will display the results. danubian@hotmail.com Javascript 3 10-28-2004 07:27 PM



Advertisments