Solved

C++, HTML and forms

Posted on 2000-04-02
60
402 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:milalik
  • 38
  • 21
60 Comments
 

Expert Comment

by:crow_nv
Comment Utility
You can try this search engine. It's
easy to use and to remake for your needs

http://technotrade.com/cgi/search.html
0
 

Author Comment

by:milalik
Comment Utility
I think that is in perl and not C++
0
 

Author Comment

by:milalik
Comment Utility
not what I am looking for
0
 

Author Comment

by:milalik
Comment Utility
help!
0
 
LVL 1

Accepted Solution

by:
gaggio earned 150 total points
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
Sorry about the wrong initialization string: you should remove the ">>" of course.
Replace it by:
printf("Content-type: text/html\n\n");

0
 

Author Comment

by:milalik
Comment Utility
Adjusted points from 50 to 80
0
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
It is extremely important for me to get this working.
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
Yes, Milalik. WHATEVER you printf or cout in your program is basically the web page that will appear in the browser!
0
 

Author Comment

by:milalik
Comment Utility
Adjusted points from 80 to 100
0
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
Please let me know if you sent the code by email (if you do) by posting a comment here!
0
 

Author Comment

by:milalik
Comment Utility
gaggio... I would let you know, I'll send it through e-mail as soon as I finish it.
thanx
0
 

Author Comment

by:milalik
Comment Utility
Adjusted points from 100 to 114
0
 

Author Comment

by:milalik
Comment Utility
This thursady or friday I'll send some code to your e-mail
thanx
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
Ok.
I'm waiting for it!
What IDE are you using? Visual C++?
0
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
Well it is going to be UNIX as of now.
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
All right
You should receive the files soon
0
 

Author Comment

by:milalik
Comment Utility
Adjusted points from 114 to 150
0
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
replied
0
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
So in the e-mail you say to change even the checkbox name to town?
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
I think there is something worng with my forms. or I have the database in a different place than the exe file
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
make cgi-bin directory executable?

according to the instructions I got it is the right directory
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
should i set it to that?
0
 

Author Comment

by:milalik
Comment Utility
You can view it now. But if you put a text in it, it does prompt you to download the exe file
0
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
I am using the get method in the form
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
Apache Server 1.3 or 1.4
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
will do it to see what happens.
0
 

Author Comment

by:milalik
Comment Utility
It stills prompts me to download it if it is as an exe file. Even with the code you suggested
0
 
LVL 1

Expert Comment

by:gaggio
Comment Utility
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
 

Author Comment

by:milalik
Comment Utility
ok thanx
i'll post any other questions later or e-mail you.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 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

9 Experts available now in Live!

Get 1:1 Help Now