C++, HTML and forms

Hi everyone. I am trying to do a search engine using C++. I know data structures in C++. I have an idea of what I want to do but i need to know how can I make my data structures work with a search engine. How do they work using forms. I have also a knowledge of Html. You help will be appreciated a lot. Here is what i want to do:

a seach engine of Restaurants

Lets first talk about how would i like the search engine page to look. It would be something like this.
-----------
            Search
-----------
0 By Name
0 By Town

I have to have two options for searching. One would be by name and the other one would be by town. The Towns would always be the same. Lets say i have this:

List of towns:
1.Aguadilla
2.Cabo Rojo
3. Isabela
4.Mayaguez
5. San Juan

From that list i will have a pointer to the record of restaurants in that town.The records will look like this:

Name of restaurant
Type of food
next


Next will be a pointer to the next restaurant record in the town.For an example if the person selects Aguadilla, all the restaurants in Aguadilla will appear in a page with the info of their name and type of food.

Questions:
1. How do I implement a C++ program in a webpage?

2. How would a sequential search on the towns be done so that it would give all the restaurants in that town?

3. i'm planning to use this example to implement the town search using a binary search tree which would have the towns in its node and from its node it would have a pointer to the records of restaurants in the towns.

4. The part of the search by name is gonna be done using a hash tables of the restaurant names which would be like 100 of them divided in the towns. The names of the Restaurants in the hash table would be encodes if possibles using six digit numbers and would have a link to the records with the restaurants info as before.

thanx
milalikAsked:
Who is Participating?
 
gaggioCommented:
Well, if you know C++ well compared to Perl, go ahead and code?
I don't really understand what your problem is.
The only thing you have to know about a CGI script, is that when you STDOUT something, it is read by the browser as HTML.
The first string to output is critical: it has to be something that says: "Start of the document", and for a common HTML page to output, it is usually "Content-type: text/html\n\n"

So... Just program the normal way, and output this string as the first thing you STDOUT.

Then, you can output whatever you want because it is going to be considered as text, but usually you output something that the browser understands, i.e. HTML.
 
Well, there is also another important thing: your program should reside in the cgi-bin directory of your webserver and have the right permissions to be executed properly.

That's all you need to know!
0
 
crow_nvCommented:
You can try this search engine. It's
easy to use and to remake for your needs

http://technotrade.com/cgi/search.html
0
 
milalikAuthor Commented:
I think that is in perl and not C++
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
milalikAuthor Commented:
not what I am looking for
0
 
milalikAuthor Commented:
help!
0
 
milalikAuthor Commented:
can you explain a little more about your last comment?
>>The only thing you have to know about >>a CGI script, is that when you STDOUT >>something, it is read by the browser >>as HTML.
>>The first string to output is >>critical: it has to be something that >>says: "Start of the document", and >>for a common HTML page to output, it >>is usually "Content-type: >>text/html\n\n"

>>So... Just program the normal way, >>and output this string as the first >>thing you STDOUT.

can you provide a little example?
0
 
gaggioCommented:
Well, ok, here it is:

void main(void){
// required initialization:
printf("Content-type: >>text/html\n\n");

// now, do your stuff here
whatever(param1, param2);

// if you print stuff with printf,or
// cout, it is going to be seen in the browser as HTML code:
printf("<B>It's almost the end of the program"</B>);

}

Is that enough?
The best, is, of course, to output a full HTML page, just like if you were designing a web page, but you don't need too.
If this is what you wanted, though, you should then do first (after the content-type stuff):
printf("<HTML><HEAD><TITLE>This is my page</TITLE></HEAD><BODY>");

.... do your stuff and output HTML page in function of your program here
.... and at the end:
printf("</BODY></HTML>");

GOT IT???
0
 
gaggioCommented:
Sorry about the wrong initialization string: you should remove the ">>" of course.
Replace it by:
printf("Content-type: text/html\n\n");

0
 
milalikAuthor Commented:
Adjusted points from 50 to 80
0
 
milalikAuthor Commented:
I want to output a complete HTML files with the results. I am using classes to do the searching routines since I have to use Data structures in C++. Does this affect the classes or just the main program?

So I just basically do the HTML inside the main program? What about if I want to do a form?So people write and select the kind of search?
0
 
gaggioCommented:
Milalik, the concept is very easy: anything that you output by using printf or cout will be read by the browser.
You want a form?
So just output it by doing something like:
printf("<FORM action=""youraction""><INPUT type=""button"">.... whatever ... </FORM>");

It is not complicated at all. It has nothing to do with the classes you use in your program: what you printf or cout in your classes also goes to the browser.
So you could have a class that is called
class form {
form();
~form();
print(); // function that cout the form
         // using printf or cout
};

The same way, you can generate anything that is HTML: tables, style-sheets, even JavaScript if you want!

Do you understand?

The only thing that you have to be careful of is that you need two "" whenever in the HTML you want to output the character ". Simply because C++ needs that.
0
 
milalikAuthor Commented:
So basically i shall printf or cout whatever I want in my programs and that way I would be able to do what I want?
0
 
milalikAuthor Commented:
Sorry If my questions seem redundant but I really want to understand this completely. You know of any books I can get on this?
0
 
milalikAuthor Commented:
It is extremely important for me to get this working.
0
 
gaggioCommented:
All right.
Let me see.
I'll give you some pointers in a little time.
But could you tell me what you did not understand yet?
0
 
gaggioCommented:
Yes, Milalik. WHATEVER you printf or cout in your program is basically the web page that will appear in the browser!
0
 
milalikAuthor Commented:
Adjusted points from 80 to 100
0
 
milalikAuthor Commented:
If i post one of the programs I made with the classes it uses will you use it as an example to guide me understand how to set the form and it working?
0
 
gaggioCommented:
Yes.
If you post a big chunk of code, please send it to ms_sucks40@hotmail.com
I'll download the code there and help you.
If it is small, then just paste it here.
0
 
gaggioCommented:
Please let me know if you sent the code by email (if you do) by posting a comment here!
0
 
milalikAuthor Commented:
gaggio... I would let you know, I'll send it through e-mail as soon as I finish it.
thanx
0
 
milalikAuthor Commented:
Adjusted points from 100 to 114
0
 
milalikAuthor Commented:
This thursady or friday I'll send some code to your e-mail
thanx
0
 
gaggioCommented:
Ok.
I'm waiting for it!
What IDE are you using? Visual C++?
0
 
milalikAuthor Commented:
Visual C++ and g++, gnu compiler. I need to know if the extension of the compile file would be .exe or .cgi
I'm sending you now the part that does the search by location because the search by name hasn't been finish. i commented the prgram the most I could telling you what I wanted. i would like you to add comments to the things you add.

thanx
0
 
milalikAuthor Commented:
Visual C++ and g++, gnu compiler. I need to know if the extension of the compile file would be .exe or .cgi
I'm sending you now the part that does the search by location because the search by name hasn't been finish. i commented the prgram the most I could telling you what I wanted. i would like you to add comments to the things you add.

thanx
0
 
gaggioCommented:
All right.
I'll help you. I'll have a look at it during the day and should be able to send it back tonight.
Give me more information about the webserver that will run your script: what platform is it running on: Linux, Unix, WindowsNT?
This will help me put more relevant comments
0
 
milalikAuthor Commented:
Well it is going to be UNIX as of now.
0
 
gaggioCommented:
If I were you, I would use Perl to do what you want.
I can still help you with C++, but could you tell me why you don't want to
use Perl?
0
 
milalikAuthor Commented:
I use C++. It is what I know, and would like to do it in that programming language. Do something different. Apart that what i sent you is just part of what I am doing. There is another part of the search that is gonna be made using restaurant names which is gonna de made using some kind of data structure in C++. I am working on that part right now. I just want to see the one I sent you, so I can learn from it and see if I can do the part thats missing by myself. If I need help. I would ask you again.

By the way i sent you a mail cuz the file you send I was unable to download.

thanx again
0
 
gaggioCommented:
I still did something to help you milalik, because I did not really need
the form to understand your project.
Did you get my email?
I pressed reply-to and then I attached
a tar file with working code for your
problem.
Tell me if you did not get it and if it is the case, give me a working email address!
gaggio
0
 
milalikAuthor Commented:
I got the e-mail but the file didn't download completely. When it ended downloading and I opened it it says the file was not complete. Try sending it to milalic@coqui.net.

Thanx again
0
 
gaggioCommented:
All right
You should receive the files soon
0
 
milalikAuthor Commented:
Adjusted points from 114 to 150
0
 
milalikAuthor Commented:
I am having problems setting my form. Sent you an e-mail with it. to see if you can help me. the program compiled okay.

thanx
0
 
gaggioCommented:
replied
0
 
milalikAuthor Commented:
I asked about the cgi-bin stuff I have to put on action. is it correct the way I put it in the form?
0
 
milalikAuthor Commented:
So in the e-mail you say to change even the checkbox name to town?
0
 
gaggioCommented:
no, not the checkbox name
EACH INPUT MUST HAVE A DIFFERENT NAME
town is the one for your textfield, the only one I am handling in the program

did you try to run the program yet?
what happens when you press submit?
0
 
milalikAuthor Commented:
the form:





<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
   <meta name="generator" content="Microsoft FrontPage 4.0">
   <meta name="GENERATOR" content="Mozilla/4.7 [en] (X11; I; Linux 2.2.14 i686) [Netscape]">
   <title>Search Engine</title>
</head>
<body>
<form action="./cgi-bin/string.exe" method="get"><input scr="mu.jpg" type="image">
<p><input type="text" name="town" size="24"><input type="submit" name="submitButtonName">
<p><input type="checkbox" value="checkboxValue" name="town">By Name
<p><input type="checkbox" value="checkboxValue" name="town">By Location
</body>
</html>

0
 
milalikAuthor Commented:
It goes to here:http://amadeus.uprm.edu/~banjo/cgi-bin/string.exe?town=Aguadilla&submitButtonName=Submit+Query&town=checkboxValue


the page is at:

http://amadeus.uprm.edu/~banjo

don't know what is wrong. The search is supposed to be done by location.



0
 
milalikAuthor Commented:
I think there is something worng with my forms. or I have the database in a different place than the exe file
0
 
gaggioCommented:
Please read carefully what I'm saying. In the form above, you give the same name to each element of the form. This is totally wrong!
Give the names town, check1 and check2 for example. Not 3 times town!!!!
0
 
milalikAuthor Commented:
Did this:




<html>

      <head>
            <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
            <meta name="generator" content="Microsoft FrontPage 4.0">
            <title>Search Engine</title>
      </head>

      <body>
            <form action=".\cgi-stringg.exe" method="get">
            <p><input type="text" name="town" size="24"> <input type="submit" name="submitButtonName"></p>
            <p><input type="checkbox" value="checkboxValue" name="checkboxName1">By Name</p>
            <p><input type="checkbox" value="checkboxValue" name="checkboxName2">By Location
      </body>

</html>



0
 
milalikAuthor Commented:
I fixed that. still getting either the same thing I told before, or it prompts to see if I want to download the file
0
 
gaggioCommented:
did you set up the cgi file/directory permissions right?
Make the cgi-bin directory executable and the program also.
Make sure that the cgi-bin directory is the one expected by the web server (contact your admin)
0
 
milalikAuthor Commented:
make cgi-bin directory executable?

according to the instructions I got it is the right directory
0
 
gaggioCommented:
do a chmod 777 on the stringg.exe file and the cgi-bin directory.
can you at least see the form in the browser?
0
 
milalikAuthor Commented:
should i set it to that?
0
 
milalikAuthor Commented:
You can view it now. But if you put a text in it, it does prompt you to download the exe file
0
 
milalikAuthor Commented:
What i am dooing wrong? I have heard sometimes you have to change it to cgi the extension instead of exe. is that right?
0
 
milalikAuthor Commented:
The .cgi extension seems to not be supported. Remeber this is for linux

my cgi-bin is in a folder called html_public. There I have my form and the cgi-bin.
0
 
milalikAuthor Commented:
I am using the get method in the form
0
 
gaggioCommented:
Ok.
Well, those questions will only be answered right by your sysadmin, since I don't know what kind of webserver he is using.
If you are sure that the cgi-bin directory setup is right but the browser prompts for download, it means that the webserver does not know the program is an executable.
Contact your sysadmin!

Yes, you could try changing the extensions to .pl, .cgi, or no extension.

Make sure that all the time ALL-USERS have the right to execute the program
0
 
milalikAuthor Commented:
Apache Server 1.3 or 1.4
0
 
gaggioCommented:
Yes, but what is important is the configuration of the server.
Try to create a simple cgi in perl and execute it. Copy and paste this into a text file, put it in the cgi-bin directory and set it as executable, then read it by an http request to your browser. It should display the phrase " it works".
-----------------------------------
#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

print "it works";

-----------------------
to set the first line correctly, do a "whereis perl" command

0
 
milalikAuthor Commented:
will do it to see what happens.
0
 
milalikAuthor Commented:
It stills prompts me to download it if it is as an exe file. Even with the code you suggested
0
 
gaggioCommented:
seriously, contact your sysadmin and ask him about cgi scripting. Or read documentation if some is available to you. I'm sorry that at this point I can't help you more than that. If you did everything the way I described it in this forum, it should be ok, but it is not apparently.
0
 
milalikAuthor Commented:
ok thanx
i'll post any other questions later or e-mail you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.