Hi everyone! I am having some difficulty with my code here. I wrote a prgraom that is supposed to receive a non-determined number of fields from an HTML form and return their values back to a browser. I feel like I am almost finished but when I open up the html document on the web the input isn't coming out right.Do you think its the debug code? Thanks for the help!!! Here is my code:

#include <iostream>        
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctype.h>

using namespace std;

/* Structure */
   struct FORM 
{
    char name[65]; 
    char data[65]; 
};

/* Function Prototypes */
   int equalcount(string);
   FORM * create_array(int);
   void getData(string, FORM *);
   string param(string, FORM *);

/* Main Function */
int main()
{

    string qs(getenv("QUERY_STRING")); 
    cout << "Content-type:text/html\n\n";
//    string qs = "name=Katy&gift=iPod&gender=girl&reason=goodallyear";


   cout << "Returned data from web: " << qs << endl; 

    int equal;
    equal = equalcount(qs);
    FORM *dyn_array;
    dyn_array = create_array(equal);
    
    getData(qs, dyn_array);


    cout << "<html><head>";
    cout << "<title>color</title></head>";
    cout << "<body>";
    
    
    string gift = param("gift", dyn_array); 
    string name = param("name", dyn_array); 
    string gender = param("gender", dyn_array);
    string reason = param("reason", dyn_array);
    
    cout << "<html>" << endl;
    cout << "<head>" << endl;
    cout << "<title>Your Christmas Wish List!</title>" << endl;
    cout << "</head>" << endl;
    cout << "<body>" << endl;
    cout << "<font color=\"#FF9933\">" << endl;
    cout << "<body bgcolor=\"#FFFFCC\">" << endl;
    cout << "<center>" << endl;
    cout << "</center>" << endl;
    
    cout << "<b>Dear Santa, </b><BR>\n";
    cout << endl; 
    cout << "<b>The one thing I want most for Christmas is " << gift << ". </b><BR>\n";
    cout << "<b>The reason I really deserve " << gift << " is because I have been a very good " << gender;
    cout << "most of the year! </b><BR>\n";
    cout << "<b>I also deserve this gift because " << reason << ".</b>,\n";
    cout << endl;
    cout << "<b>Love," << name << "</b><BR>\n";
    cout << "</font></body>" << endl;
    cout << "</html>" << endl;
    
    
    system("PAUSE");
    return 0;
}





int equalcount(string qs)
{
    int index = 0, equal = 0;
    
    for (index; index < qs.length(); index++)
    {
        if (qs[index] == '=')
        {
            equal++;
        }
    }
    return equal;
}

FORM *create_array(int equal)
{
    FORM *array;
    array = new FORM[equal];
    return array;
}


void getData(string qs, FORM *dyn_array)
{
 
       int x = 0;
    int y = 0;
    int i = 0;
//    cout << "debug with qs.length: " << qs.length() << "< br>";    
        while( x < qs.length()) 
            {                
        while (isalnum(qs[x]))
            {
            dyn_array[i].name[y] = qs[x];
//            cout << "debug with name[" << y << "]: " << dyn_array[i].name[y] << "< br>";
            y++;
            x++;
            }    
        dyn_array[i].name[y] = '\0';
//        cout << "name: " << dyn_array[i].name << endl << "< br>";
           y = 0;
        while (!(isalnum( qs[x])))
            {
            x++;
            }
        
            {
            dyn_array[i].data[y] = qs[x];
//            cout << "debug with data[" << y << "]: " << dyn_array[i].data[y] << "< br>";
            y++;
            x++;
            }
        x++;
//        cout << "debug with x: " << x << "";
        
        dyn_array[i].data[y] = '\0';
//        cout << "data: " << dyn_array[i].data << endl << "< br>";
        y = 0;
        i++;
    }
    
}

string param(string input, FORM *dyn_array)
{
    int index=0;
    string ans;
    for(index=0; index<20; index++)
    {
        if(input == dyn_array[index].name)
        {
            cout << input << endl;
            ans = dyn_array[index].data; 

            return ans;
        }
    }
    return "";
}

This is the first page on the web:
The gift you want most for Christmas:
My name on Santa's List:

Gender(boy/girl):

Why do you deserve this gift?

and then a submit button allows the user to input their info. Now when they hit submit their information should be outputted saying:
Dear Santa,
The one thing I want most for Christmas is <<the gift input<<
The reason I really deserve << the gift input << is because I have been a very good << gender input << most of the year! I also deserve this gift because << reason input<<

>when I open up the html document on the web the input isn't coming out right.
Give more information. What exactly is outputted from the program? Provide the exact HTML. Then show what you were expecting. If you know, provide where you think the problem is happening. These sorts of things can help us find the problem much faster. Thanks.

Here is the html site http://207.62.192.204/~gen69/christmaskp.html if you fill in the information it isn't outputting it correctly and I'm not sure how to make it work properly and am wondering if it is the debug statement that is wrong?

Your logic for getNum() is really messed up -- I'm not exactly sure what you are trying to put into FORM::name and FORM::data. From the looks of it, you're trying to copy the names of the variables from the original string into FORM::name, but I'm all confused now, and it doesn't really copy much into the FORM::data, which is because you forgot a while() statement or something here:

{
            dyn_array[i].data[y] = qs[x];
//            cout << "debug with data[" << y << "]: " << dyn_array[i].data[y] << "< br>";
            y++;
            x++;
            }

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.