milalik
asked on
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
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
ASKER
I think that is in perl and not C++
ASKER
not what I am looking for
ASKER
help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
>>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?
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???
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
.... do your stuff and output HTML page in function of your program here
.... and at the end:
printf("</BODY></HTML>");
GOT IT???
Sorry about the wrong initialization string: you should remove the ">>" of course.
Replace it by:
printf("Content-type: text/html\n\n");
Replace it by:
printf("Content-type: text/html\n\n");
ASKER
Adjusted points from 50 to 80
ASKER
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?
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?
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""><INP UT 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.
You want a form?
So just output it by doing something like:
printf("<FORM action=""youraction""><INP
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.
ASKER
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?
ASKER
Sorry If my questions seem redundant but I really want to understand this completely. You know of any books I can get on this?
ASKER
It is extremely important for me to get this working.
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?
Let me see.
I'll give you some pointers in a little time.
But could you tell me what you did not understand yet?
Yes, Milalik. WHATEVER you printf or cout in your program is basically the web page that will appear in the browser!
ASKER
Adjusted points from 80 to 100
ASKER
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?
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.
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.
Please let me know if you sent the code by email (if you do) by posting a comment here!
ASKER
gaggio... I would let you know, I'll send it through e-mail as soon as I finish it.
thanx
thanx
ASKER
Adjusted points from 100 to 114
ASKER
This thursady or friday I'll send some code to your e-mail
thanx
thanx
Ok.
I'm waiting for it!
What IDE are you using? Visual C++?
I'm waiting for it!
What IDE are you using? Visual C++?
ASKER
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
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
ASKER
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
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
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
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
ASKER
Well it is going to be UNIX as of now.
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?
I can still help you with C++, but could you tell me why you don't want to
use Perl?
ASKER
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
By the way i sent you a mail cuz the file you send I was unable to download.
thanx again
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
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
ASKER
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
Thanx again
All right
You should receive the files soon
You should receive the files soon
ASKER
Adjusted points from 114 to 150
ASKER
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
thanx
replied
ASKER
I asked about the cgi-bin stuff I have to put on action. is it correct the way I put it in the form?
ASKER
So in the e-mail you say to change even the checkbox name to town?
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?
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?
ASKER
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.e xe" 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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-type" content="text/html;charset
<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.e
<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>
ASKER
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.
the page is at:
http://amadeus.uprm.edu/~banjo
don't know what is wrong. The search is supposed to be done by location.
ASKER
I think there is something worng with my forms. or I have the database in a different place than the exe file
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!!!!
Give the names town, check1 and check2 for example. Not 3 times town!!!!
ASKER
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>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset
<meta name="generator" content="Microsoft FrontPage 4.0">
<title>Search Engine</title>
</head>
<body>
<form action=".\cgi-stringg.exe"
<p><input type="text" name="town" size="24"> <input type="submit" name="submitButtonName"></
<p><input type="checkbox" value="checkboxValue" name="checkboxName1">By Name</p>
<p><input type="checkbox" value="checkboxValue" name="checkboxName2">By Location
</body>
</html>
ASKER
I fixed that. still getting either the same thing I told before, or it prompts to see if I want to download the file
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)
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)
ASKER
make cgi-bin directory executable?
according to the instructions I got it is the right directory
according to the instructions I got it is the right directory
do a chmod 777 on the stringg.exe file and the cgi-bin directory.
can you at least see the form in the browser?
can you at least see the form in the browser?
ASKER
should i set it to that?
ASKER
You can view it now. But if you put a text in it, it does prompt you to download the exe file
ASKER
What i am dooing wrong? I have heard sometimes you have to change it to cgi the extension instead of exe. is that right?
ASKER
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.
my cgi-bin is in a folder called html_public. There I have my form and the cgi-bin.
ASKER
I am using the get method in the form
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
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
ASKER
Apache Server 1.3 or 1.4
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
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
ASKER
will do it to see what happens.
ASKER
It stills prompts me to download it if it is as an exe file. Even with the code you suggested
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.
ASKER
ok thanx
i'll post any other questions later or e-mail you.
i'll post any other questions later or e-mail you.
easy to use and to remake for your needs
http://technotrade.com/cgi/search.html