I'm new at CGI. I want to create a program in CGI using C language which takes 2 integers as input from an html form and output the multiplication of them in a html form.I tried to use "GET" method to do this program (using the enviroment variable QUERY_STRING) and it is ok, but I want to learn how to make this program using the "POST "method(accessing the input data using stdin). Here is the program I made using "GET".Can someone help me with the program if I want to use "POST" so where the input data are read by stdin. I know that there are tutorials cause I've been searching for hours and I know very well how this works in theory, but I didn't find anywhere a concrete example of a c program using "POST".The html form :
<form action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/mult.cgi">
<div><label>Multiplicand 1: <input name="m" size="5"></label></div>
<div><label>Multiplicand 2: <input name="n" size="5"></label></div>
<div><input type="submit" value="Multiply!"></div>
</form>
The program in c:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *data;
long m,n;
printf("%s%c%c\n",
"Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<TITLE>Multiplication results</TITLE>\n");
printf("<H3>Multiplication results</H3>\n");
data = getenv("QUERY_STRING");
if(data == NULL)
printf("<P>Error! Error in passing data from form to script.");
else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
printf("<P>Error! Invalid data. Data must be numeric.");
else
printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
return 0;
}