Solved

c++, cgi and HTML forms..

Posted on 2001-07-24
2
211 Views
Last Modified: 2013-12-25
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
Comment
Question by:jurij
2 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 200 total points
ID: 6319333
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
 

Author Comment

by:jurij
ID: 6329481
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question