Solved

c++, cgi and HTML forms..

Posted on 2001-07-24
2
205 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now