Link to home
Start Free TrialLog in
Avatar of jurij
jurij

asked on

c++, cgi and HTML forms..

Can anyone help me with html forms and c++ trough CGI..

I don't know how to retrive data I entered in the form..
Here is a short example on how do I get the data(I'm not sure if I'm doing it right)..

-------------------------------------------------------
#include <iostream.h>
void main()
{
int age;
char name;
cout << "Content-Type: text/html\r\n\r\n" << endl;
cout << "
   <HTML>
    <HEAD>
     <TITLE> TEST PAGE! </TITLE>
     </HEAD>
      <BODY>
       <form action=\"/cgi-bin/test2\" method=POST>
        Enter your name: <input type=text name=\"name\"><p>
        <input type=submit>
       </form>
      </BODY>
    </HTML>  " << endl;
return 0;
}
-------------------------------------------------------

I now want to create file named test2, that shows the data I have entered..

I was looking at c++/cgi tutorials but it seems everyone are using there own rutines on how to retrive
inputed data..
I would much apreciate if you would give me a short example..
THANK YOU!
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jurij
jurij

ASKER

char *str = (char *)NULL;
errno=0;
if (getenv("CONTENT_LENGTH")>0 && errno==0) {
  str = getenv('QUERY_STRING");
  if (str!=(char *)NULL && errno==0) {
     // now you need to split str into name-value pairs, for example using strtok
  }
}
--------------------------------------------------------

If I output, I get "REQUEST_URL=/cgi-bin/name"
What am I doing wrong?