Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

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!
0
jurij
Asked:
jurij
1 Solution
 
ahoffmannCommented:
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
   }
}
0
 
jurijAuthor Commented:
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?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now