onyourmark
asked on
Apache /WAMP not working
Hello. I cannot seem to get WAMP to work right. It was working but now even though I "start all services" the WAMP icon in the icon tray has red in it. Any one have any suggestions on what I can do? I tried reinstalling but it did not help. It says server online but it is still red.
Thanks.
Thanks.
check the logs. there might be some problem with httpd.conf file. logs must give you something about what and where is wrong.
ASKER
I got it going by going to services but I cannot connect to localhost. I have put the recent logs here
[Sun Oct 17 22:31:35 2010] [notice] Child 7944: Exit event signaled. Child process is ending.
[Sun Oct 17 22:31:36 2010] [notice] Child 7944: Released the start mutex
[Sun Oct 17 22:31:37 2010] [notice] Child 7944: All worker threads have exited.
[Sun Oct 17 22:31:37 2010] [notice] Child 7944: Child process is exiting
[Sun Oct 17 22:31:37 2010] [notice] Parent: Child process exited successfully.
[Sun Oct 17 22:31:40 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sun Oct 17 22:31:40 2010] [notice] Server built: Dec 10 2008 00:10:06
[Sun Oct 17 22:31:40 2010] [notice] Parent: Created child process 7276
[Sun Oct 17 22:31:41 2010] [notice] Child 7276: Child process is running
[Sun Oct 17 22:31:41 2010] [notice] Child 7276: Acquired the start mutex.
[Sun Oct 17 22:31:41 2010] [notice] Child 7276: Starting 64 worker threads.
[Sun Oct 17 22:31:41 2010] [notice] Child 7276: Starting thread to listen on port 8080.
[Sun Oct 17 22:31:59 2010] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun Oct 17 22:31:59 2010] [notice] Child 7276: Exit event signaled. Child process is ending.
[Sun Oct 17 22:32:00 2010] [notice] Child 7276: Released the start mutex
[Sun Oct 17 22:32:01 2010] [notice] Child 7276: All worker threads have exited.
[Sun Oct 17 22:32:01 2010] [notice] Child 7276: Child process is exiting
[Sun Oct 17 22:32:01 2010] [notice] Parent: Child process exited successfully.
[Sun Oct 17 22:32:10 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sun Oct 17 22:32:10 2010] [notice] Server built: Dec 10 2008 00:10:06
[Sun Oct 17 22:32:10 2010] [notice] Parent: Created child process 9836
[Sun Oct 17 22:32:10 2010] [notice] Child 9836: Child process is running
[Sun Oct 17 22:32:10 2010] [notice] Child 9836: Acquired the start mutex.
[Sun Oct 17 22:32:10 2010] [notice] Child 9836: Starting 64 worker threads.
[Sun Oct 17 22:32:10 2010] [notice] Child 9836: Starting thread to listen on port 8080.
[Sun Oct 17 22:37:40 2010] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun Oct 17 22:37:40 2010] [notice] Child 9836: Exit event signaled. Child process is ending.
[Sun Oct 17 22:37:41 2010] [notice] Child 9836: Released the start mutex
[Sun Oct 17 22:37:42 2010] [notice] Child 9836: All worker threads have exited.
[Sun Oct 17 22:37:42 2010] [notice] Child 9836: Child process is exiting
[Sun Oct 17 22:37:42 2010] [notice] Parent: Child process exited successfully.
[Sun Oct 17 22:37:44 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sun Oct 17 22:37:44 2010] [notice] Server built: Dec 10 2008 00:10:06
[Sun Oct 17 22:37:44 2010] [notice] Parent: Created child process 3404
[Sun Oct 17 22:37:44 2010] [notice] Child 3404: Child process is running
[Sun Oct 17 22:37:44 2010] [notice] Child 3404: Acquired the start mutex.
[Sun Oct 17 22:37:44 2010] [notice] Child 3404: Starting 64 worker threads.
[Sun Oct 17 22:37:44 2010] [notice] Child 3404: Starting thread to listen on port 8080.
[Sun Oct 17 22:37:46 2010] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun Oct 17 22:37:46 2010] [notice] Child 3404: Exit event signaled. Child process is ending.
[Sun Oct 17 22:37:47 2010] [notice] Child 3404: Released the start mutex
[Sun Oct 17 22:37:48 2010] [notice] Child 3404: All worker threads have exited.
[Sun Oct 17 22:37:48 2010] [notice] Child 3404: Child process is exiting
[Sun Oct 17 22:37:48 2010] [notice] Parent: Child process exited successfully.
[Sun Oct 17 22:37:48 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sun Oct 17 22:37:48 2010] [notice] Server built: Dec 10 2008 00:10:06
[Sun Oct 17 22:37:48 2010] [notice] Parent: Created child process 8168
[Sun Oct 17 22:37:48 2010] [notice] Child 8168: Child process is running
[Sun Oct 17 22:37:48 2010] [notice] Child 8168: Acquired the start mutex.
[Sun Oct 17 22:37:48 2010] [notice] Child 8168: Starting 64 worker threads.
[Sun Oct 17 22:37:48 2010] [notice] Child 8168: Starting thread to listen on port 8080.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi I tried your suggestion
http://localhost:8080/
and it worked. Then I changed httpd.conf to 80 and tried it without the :8080 but it still worked but if i try just http://localhost it does not. Oops! Google Chrome could not connect to localhost
http://localhost:8080/
and it worked. Then I changed httpd.conf to 80 and tried it without the :8080 but it still worked but if i try just http://localhost it does not. Oops! Google Chrome could not connect to localhost
are you able to open it in another browser?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi JEROME,
Thanks. It worked as far as what you said. I mean I could get the page http://localhost:81 to work.
However, when I try to access
http://localhost:81/cgi-bin/web.pl
I get an error like 500 Internal Sever Error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
I have two apache folders on my computer. I am not sure if the cgi-bin directory is in the right place. Do you know how I can fix it?
Thanks again.
Thanks. It worked as far as what you said. I mean I could get the page http://localhost:81 to work.
However, when I try to access
http://localhost:81/cgi-bin/web.pl
I get an error like 500 Internal Sever Error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
I have two apache folders on my computer. I am not sure if the cgi-bin directory is in the right place. Do you know how I can fix it?
Thanks again.
onyourmark, i think you should open a separate ticket for this one. your original question was XAMP not working, and now it seems to have been working then the problem is resolved. if you are having any other problems then it should be asked using a separate ticket.
ASKER
Thanks!
Hi,
Cool buddy !!!
As you have mentioned that you have two xampp folders, I thought you tried to run the PERL SCRIPT which is in the different XAMPP installation folder than the folder where you have made the change in the apache configuration file.
...So kindly run the perl script inside the xampp folder where you have changed the httpd.conf file .....
And the cgi-bin folder / directory must be normally inside xampp folder (c://xampp/cgi-bin) so you can run the PERL script inside the directory as http://localhost:81/cgi-bin/yourperlscript.pl
IF it helps then its cool else let me know !!!!
Regards,
Jerome Dennis D
Cool buddy !!!
As you have mentioned that you have two xampp folders, I thought you tried to run the PERL SCRIPT which is in the different XAMPP installation folder than the folder where you have made the change in the apache configuration file.
...So kindly run the perl script inside the xampp folder where you have changed the httpd.conf file .....
And the cgi-bin folder / directory must be normally inside xampp folder (c://xampp/cgi-bin) so you can run the PERL script inside the directory as http://localhost:81/cgi-bin/yourperlscript.pl
IF it helps then its cool else let me know !!!!
Regards,
Jerome Dennis D
ASKER
Hi. Thanks for posting.
I am still getting that same error. I have the script called web.pl
at
C:\wamp\cgi-bin
then I try http://localhost:81/cgi-bin/web.pl
and get the error.
If I put Test.htm
at
C:\wamp\www
and try
http://localhost:81/Test.htm
Test shows up fine.
I am still getting that same error. I have the script called web.pl
at
C:\wamp\cgi-bin
then I try http://localhost:81/cgi-bin/web.pl
and get the error.
If I put Test.htm
at
C:\wamp\www
and try
http://localhost:81/Test.htm
Test shows up fine.
Kindly make sure the following things,
1. Your web.pl inside your C drive is the same wamp folder where you have changed the httpd.conf file..
2. your web.pl has no bugs in it
If so then kindly restart your wamp once again and try run with http://localhost:81/cgi-bin/printenv.pl
FYI : i have attached another PERL script try with this script and let me know whether its running .
Save the file as printenv.pl with file type 'all files'
IF it helps then its cool else let me know !!!!
Regards,
Jerome Dennis D
1. Your web.pl inside your C drive is the same wamp folder where you have changed the httpd.conf file..
2. your web.pl has no bugs in it
If so then kindly restart your wamp once again and try run with http://localhost:81/cgi-bin/printenv.pl
FYI : i have attached another PERL script try with this script and let me know whether its running .
Save the file as printenv.pl with file type 'all files'
IF it helps then its cool else let me know !!!!
Regards,
Jerome Dennis D
#!"C:\xampp\perl\bin\perl.exe"
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
ASKER
Hi Dennis. I tried saving the code you wrote as environ.pl and putting it in the cgi-bin folder. When I go to
http://localhost:81/cgi-bin/environ.pl
I get the
Oops! This link appears to be broken.
message.
When I go to
http://localhost:81/cgi-bin/printenv.pl
I get:
COMSPEC="C:\Windows\system 32\cmd.exe "
DOCUMENT_ROOT="C:/wamp/www /"
GATEWAY_INTERFACE="CGI/1.1 "
HTTP_ACCEPT="application/x ml,applica tion/xhtml +xml,text/ html;q=0.9 ,text/plai n;q=0.8,im age/png,*/ *;q=0.5"
HTTP_ACCEPT_CHARSET="ISO-8 859-1,utf- 8;q=0.7,*; q=0.3"
HTTP_ACCEPT_ENCODING="gzip ,deflate,s dch"
HTTP_ACCEPT_LANGUAGE="en-U S,en;q=0.8 "
HTTP_CONNECTION="keep-aliv e"
HTTP_HOST="localhost:81"
HTTP_REFERER="https://www.experts-exchange.com/questions/26549540/Apache-WAMP-not-working.html?cid=748"
HTTP_USER_AGENT="Mozilla/5 .0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"
PATH="C:\Perl\site\bin;C:\ Perl\bin;C :\Windows\ system32;C :\Windows; C:\Windows \System32\ Wbem;C:\Wi ndows\Syst em32\Windo wsPowerShe ll\v1.0\;C :\Program Files\QuickTime\QTSystem\; C:\strawbe rry\c\bin; C:\strawbe rry\perl\s ite\bin;C: \strawberr y\perl\bin ;C:\Progra m Files\MySQL\MySQL Server 5.1\bin;"
PATHEXT=".COM;.EXE;.BAT;.C MD;.VBS;.V BE;.JS;.JS E;.WSF;.WS H;.MSC"
QUERY_STRING=""
REMOTE_ADDR="127.0.0.1"
REMOTE_PORT="49904"
REQUEST_METHOD="GET"
REQUEST_URI="/cgi-bin/prin tenv.pl"
SCRIPT_FILENAME="C:/wamp/b in/apache/ Apache2.2. 11/cgi-bin /printenv. pl"
SCRIPT_NAME="/cgi-bin/prin tenv.pl"
SERVER_ADDR="127.0.0.1"
SERVER_ADMIN="admin@localh ost"
SERVER_NAME="localhost"
SERVER_PORT="81"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE=""
SERVER_SOFTWARE="Apache/2. 2.11 (Win32) PHP/5.3.0"
SYSTEMROOT="C:\Windows"
WINDIR="C:\Windows"
http://localhost:81/cgi-bin/environ.pl
I get the
Oops! This link appears to be broken.
message.
When I go to
http://localhost:81/cgi-bin/printenv.pl
I get:
COMSPEC="C:\Windows\system
DOCUMENT_ROOT="C:/wamp/www
GATEWAY_INTERFACE="CGI/1.1
HTTP_ACCEPT="application/x
HTTP_ACCEPT_CHARSET="ISO-8
HTTP_ACCEPT_ENCODING="gzip
HTTP_ACCEPT_LANGUAGE="en-U
HTTP_CONNECTION="keep-aliv
HTTP_HOST="localhost:81"
HTTP_REFERER="https://www.experts-exchange.com/questions/26549540/Apache-WAMP-not-working.html?cid=748"
HTTP_USER_AGENT="Mozilla/5
PATH="C:\Perl\site\bin;C:\
PATHEXT=".COM;.EXE;.BAT;.C
QUERY_STRING=""
REMOTE_ADDR="127.0.0.1"
REMOTE_PORT="49904"
REQUEST_METHOD="GET"
REQUEST_URI="/cgi-bin/prin
SCRIPT_FILENAME="C:/wamp/b
SCRIPT_NAME="/cgi-bin/prin
SERVER_ADDR="127.0.0.1"
SERVER_ADMIN="admin@localh
SERVER_NAME="localhost"
SERVER_PORT="81"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE=""
SERVER_SOFTWARE="Apache/2.
SYSTEMROOT="C:\Windows"
WINDIR="C:\Windows"
Oh dude thatz gr8 news. .your Perl Script is running on your localhost...thatz why you have got the ouput of the file (configuration) when running http://localhost:81/cgi-bin/printenv.pl ...
the only thing that you have to do is check your web.pl whether it has got any bugs or not. and if you have no problem just upload it here and let me check whether it runs fine on my localhost...
And kindly free to get back to me if you still have further problems with this...
Regards,
Jerome Dennis D
the only thing that you have to do is check your web.pl whether it has got any bugs or not. and if you have no problem just upload it here and let me check whether it runs fine on my localhost...
And kindly free to get back to me if you still have further problems with this...
Regards,
Jerome Dennis D
ASKER
Hi. I don't think it has any problems cause it was running recently but I am going to attach it here. Thanks for your patience.
By the way, when I run:
http://localhost:81/phpmyadmin/
I get that error:
Error
MySQL said: Documentation
#1045 - Access denied for user 'root'@'localhost' (using password: NO)
Could this be related to the problem?
By the way, when I run:
http://localhost:81/phpmyadmin/
I get that error:
Error
MySQL said: Documentation
#1045 - Access denied for user 'root'@'localhost' (using password: NO)
Could this be related to the problem?
#!c:/perl/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $q = CGI->new;
my $db_user = 'root';
my $db_pass = 'password';
my $db_host = 'localhost';
my $db_name = 'hotel';
my $dsn = "DBI:mysql:$db_name:$db_host;";
my $dbh = DBI->connect($dsn, $db_user, $db_pass) or die $DBI::errstr;
my $a = $q->param('a');
if ($a eq 'hotel') {
print $q->header(charset => 'UTF-8');
my $id = $q->param('id');
my $sql = 'SELECT * FROM hotel WHERE id = ?';
my $sth = $dbh->prepare($sql);
$sth->execute($id) or die $dbh->errstr;
my $row = $sth->fetchrow_hashref;
print <<HTML;
<h2>Hotel Details</h2>
<table width='90%' align='center'>
<tr><td align='right'>Name:</td><td>$row->{name}</td></tr>
<tr><td align='right'>City:</td><td>$row->{city}</td></tr>
<tr><td align='right'>Stars:</td><td>$row->{stars}</td></tr>
<tr><td align='right'>Ranking:</td><td>$row->{ranking}</td></tr>
<tr><td align='right'>greenDotRank:</td><td>$row->{greenDotRank}</td></tr>
<tr><td align='right'>services:</td><td>$row->{services}</td></tr>
</table>
<p><a href='$ENV{SCRIPT_NAME}'>Back to Main Page</a></p>
HTML
# get reviews
$sql = 'SELECT * FROM reviews WHERE hotel_id = ? LIMIT 20';
$sth = $dbh->prepare($sql);
$sth->execute($id) or die $dbh->errstr;
print "<h2>Reviews</h2>\n";
while (my $row = $sth->fetchrow_hashref) {
print "<h3>Review $row->{id} : $row->{title} on $row->{date}</h3> <p>$row->{text}</p>\n";
}
} elsif ($a eq 'reviews') {
my $page = $q->param('page') || 1;
$page = 1 if $page !~ /^\d+$/;
$page-- if $q->param('prevPage');
$page++ if $q->param('nextPage');
my $rows = 20;
my $start = ($page - 1) * $rows;
my $in_search = $q->param('in_search');
my $and_or = $q->param('and_or');
$and_or = 'AND' unless ($and_or and $and_or eq 'OR');
my $title = $q->param('title');
my $text = $q->param('text');
my $date = $q->param('date');
my $city = $q->param('city');
my $hotel_id = $q->param('hotel_id');
my (@sql, @binds);
if ($title) {
$title =~ s/([\%\_])/\\$1/g;
push @sql, "title LIKE ?";
push @binds, "%$title%";
}
if ($text) {
$text =~ s/([\%\_])/\\$1/g;
push @sql, "text LIKE ?";
push @binds, "%$text%";
}
if ($date) {
push @sql, "date = ?";
push @binds, $date;
}
if ($hotel_id) {
push @sql, "hotel_id = ?";
push @binds, $hotel_id;
}
if ($city) {
my $tmp_sth = $dbh->prepare('SELECT id FROM hotel WHERE city = ?');
$tmp_sth->execute($city);
my @hotel_ids;
while (my ($id) = $tmp_sth->fetchrow_array) {
push @hotel_ids, $id;
}
if (@hotel_ids) {
push @sql, "hotel_id IN (" . join(",", @hotel_ids) . ")";
} else {
push @sql, 0; # no result
}
}
my $sql = "SELECT * FROM reviews";
if ($in_search) {
my $where = join(" $and_or ", @sql);
$sql .= " WHERE $where";
}
$sql .= " LIMIT $start, $rows" unless $in_search;
my $sth = $dbh->prepare($sql);
$sth->execute(@binds);
my $is_and_checked = ($and_or eq 'AND') ? ' checked="checked"' : '';
my $is_or_checked = ($and_or eq 'OR') ? ' checked="checked"' : '';
my $csv_button = ($in_search) ? qq~<input type='submit' name='download_csv' value='Download as CSV' />~ : '';
### if it's CSV to download?
my $download_csv = $q->param('download_csv');
if ($download_csv) {
require Text::CSV_XS;
require IO::Scalar;
my $csv = Text::CSV_XS->new({ binary => 1 }) or
die "Cannot use CSV: " . Text::CSV_XS->error_diag();
my $filename = 'Reviews.csv';
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$filename\n\n";
$sql = 'SELECT * FROM hotel WHERE id = ?';
my $hotel_sth = $dbh->prepare($sql);
my %hotels;
my $output;
my $fh = new IO::Scalar \$output;
$fh->binmode(':utf8');
$csv->print($fh, ["ID", "NAME", "CITY", "TITLE", "TEXT", "DATE", "STARS", "RANKING", "greenDotRank", "SERVICES"]);
print $fh "\n";
while (my $row = $sth->fetchrow_hashref) {
my $hotel = $hotels{$row->{hotel_id}};
unless ($hotel) {
$hotel_sth->execute($row->{hotel_id});
($hotel) = $hotel_sth->fetchrow_hashref;
$hotels{$row->{hotel_id}} = $hotel;
}
$csv->print($fh, [$row->{id}, $hotel->{name}, $hotel->{city}, $row->{title}, $row->{text}, $row->{date}, $hotel->{stars}, $hotel->{ranking}, $hotel->{greenDotRank}, $hotel->{services}]);
print $fh "\n";
}
$output =~ s/\"\"//g;
print $output;
exit;
} else {
print $q->header(charset => 'UTF-8');
}
print <<HTML;
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<p><a href='$ENV{SCRIPT_NAME}'>Hotels</a> | Reviews</p>
<hr />
<h3>Search</h3>
<form name='srch' method='POST'>
<input type='hidden' name='in_search' value='1' />
<input type='hidden' name='a' value='reviews' />
<table border='0' width='300'>
<tr><td align='right'>AND/OR:</td><td><input type='radio' name='and_or' value='AND'$is_and_checked />AND <input type='radio' name='and_or' value='OR'$is_or_checked />OR</td></tr>
<tr><td align='right'>Title:</td><td><input type='text' name='title' size='24' value="$title" /></td></tr>
<tr><td align='right'>Text:</td><td><input type='text' name='text' size='24' value="$text" /></td></tr>
<tr><td align='right'>Date:</td><td><input type='text' name='date' size='24' value="$date" /></td></tr>
<tr><td align='right'>City:</td><td><input type='text' name='city' size='24' value="$city" /></td></tr>
<tr><td align='right'>Hotel ID:</td><td><input type='text' name='hotel_id' size='24' value="$hotel_id" /></td></tr>
<tr><td> </td><td><input type='submit' value='Search' /> $csv_button</td></tr>
</table>
</form>
<hr />
<h3>Results</h3>
HTML
unless ($q->param('in_search')) {
my $sql = 'SELECT COUNT(*) FROM reviews';
my $sth = $dbh->prepare($sql);
$sth->execute();
my ($total) = $sth->fetchrow_array;
print <<HTML;
<form name='pager' method='POST'>
<input type='hidden' name='page' value="$page" />
<input type='hidden' name='a' value='reviews' />
HTML
if ($page > 1) {
my $prev_page = $page - 1;
print qq~<input type='submit' name='prevPage' value='Prev Page' />\n~;
}
if ($start < $total - $rows) {
my $next_page = $page + 1;
print qq~<input type='submit' name='nextPage' value='Next Page' />~;
}
print "</form>\n";
}
print <<HTML;
<table width='90%' border='1' align='center'>
<tr><th>ID</th><th>Hotel</th><th>Title</th><th>Text</th><th>Date</th></tr>
HTML
$sql = 'SELECT name FROM hotel WHERE id = ?';
my $hotel_sth = $dbh->prepare($sql);
my %hotels;
while (my $row = $sth->fetchrow_hashref) {
my $hotel = $hotels{$row->{hotel_id}};
unless ($hotel) {
$hotel_sth->execute($row->{hotel_id});
($hotel) = $hotel_sth->fetchrow_array;
$hotels{$row->{hotel_id}} = $hotel;
}
print "<tr><td>$row->{id}</td><td><a href='?a=reviews&hotel_id=$row->{hotel_id}&in_search=1'>$hotel</a></td><td>$row->{title}</td><td>$row->{text}</td><td>$row->{date}</td></tr>\n";
}
print "</table></body></html>";
} else {
my $page = $q->param('page') || 1;
$page = 1 if $page !~ /^\d+$/;
$page-- if $q->param('prevPage');
$page++ if $q->param('nextPage');
my $rows = 20;
my $start = ($page - 1) * $rows;
my $in_search = $q->param('in_search');
my $and_or = $q->param('and_or');
$and_or = 'AND' unless ($and_or and $and_or eq 'OR');
my $name = $q->param('name');
my $city = $q->param('city');
my $stars = $q->param('stars');
my $services = $q->param('services');
my (@sql, @binds);
if ($name) {
$name =~ s/([\%\_])/\\$1/g;
push @sql, "name LIKE ?";
push @binds, "%$name%";
}
if ($city) {
push @sql, "city = ?";
push @binds, $city;
}
if ($stars) {
push @sql, "stars = ?";
push @binds, $stars;
}
if ($services) {
$services =~ s/([\%\_])/\\$1/g;
push @sql, "services LIKE ?";
push @binds, "%$services%";
}
my $sql = "SELECT * FROM hotel";
if ($in_search) {
my $where = join(" $and_or ", @sql);
$sql .= " WHERE $where";
}
$sql .= " LIMIT $start, $rows" unless $in_search;
my $sth = $dbh->prepare($sql);
$sth->execute(@binds);
my $is_and_checked = ($and_or eq 'AND') ? ' checked="checked"' : '';
my $is_or_checked = ($and_or eq 'OR') ? ' checked="checked"' : '';
my $csv_button = ($in_search) ? qq~<input type='submit' name='download_csv' value='Download as CSV' />~ : '';
### if it's CSV to download?
my $download_csv = $q->param('download_csv');
if ($download_csv) {
require Text::CSV_XS;
my $csv = Text::CSV_XS->new({ binary => 1 }) or
die "Cannot use CSV: " . Text::CSV_XS->error_diag();
my $filename = 'Hotels.csv';
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$filename\n\n";
binmode STDOUT, ":utf8";
$csv->print(\*STDOUT, ["ID", "NAME", "CITY", "STARS", "RANKING", "greenDotRank", "SERVICES"]);
print "\n";
while (my $row = $sth->fetchrow_hashref) {
$csv->print(\*STDOUT, [$row->{id}, $row->{name}, $row->{city}, $row->{stars}, $row->{ranking}, $row->{greenDotRank}, $row->{services}]);
print "\n";
}
exit;
} else {
print $q->header(charset => 'UTF-8');
}
print <<HTML;
<p>Hotels | <a href='$ENV{SCRIPT_NAME}?a=reviews'>Reviews</a></p>
<hr />
<h3>Search</h3>
<form name='srch' method='POST'>
<input type='hidden' name='in_search' value='1' />
<table border='0' width='300'>
<tr><td align='right'>AND/OR:</td><td><input type='radio' name='and_or' value='AND'$is_and_checked />AND <input type='radio' name='and_or' value='OR'$is_or_checked />OR</td></tr>
<tr><td align='right'>Name:</td><td><input type='text' name='name' size='24' value="$name" /></td></tr>
<tr><td align='right'>City:</td><td><input type='text' name='city' size='24' value="$city" /></td></tr>
<tr><td align='right'>Stars:</td><td><input type='text' name='stars' size='24' value="$stars" /></td></tr>
<tr><td align='right'>Services:</td><td><input type='text' name='services' size='24' value="$services" /></td></tr>
<tr><td> </td><td><input type='submit' value='Search' /> $csv_button</td></tr>
</table>
</form>
<hr />
<h3>Results</h3>
HTML
unless ($q->param('in_search')) {
my $sql = 'SELECT COUNT(*) FROM hotel';
my $sth = $dbh->prepare($sql);
$sth->execute();
my ($total) = $sth->fetchrow_array;
print <<HTML;
<form name='pager' method='POST'>
<input type='hidden' name='page' value="$page" />
HTML
if ($page > 1) {
my $prev_page = $page - 1;
print qq~<input type='submit' name='prevPage' value='Prev Page' />\n~;
}
if ($start < $total - $rows) {
my $next_page = $page + 1;
print qq~<input type='submit' name='nextPage' value='Next Page' />~;
}
print "</form>\n";
}
print <<HTML;
<table width='90%' border='1' align='center'>
<tr><th>ID</th><th>Name</th><th>City</th><th>Stars</th><th>Ranking</th><th>greenDotRank</th><th>Services</th></tr>
HTML
while (my $row = $sth->fetchrow_hashref) {
print "<tr><td>$row->{id}</td><td><a href='?a=hotel&id=$row->{id}'>$row->{name}</a></td><td>$row->{city}</td><td>$row->{stars}</td><td>$row->{ranking}</td><td>$row->{greenDotRank}</td><td>$row->{services}</td></tr>\n";
}
print "</table>";
}
1;
Hi,
For phpmyadmin problem kindly go through with these links below
http://bytes.com/topic/php/answers/160028-phpmyadmin-connect-problem
http://www.gidforums.com/t-600.html
http://hintsforums.macworld.com/showthread.php?t=58057
And regarding your PErl Script running on xampp localhost kindly undo whatever change you have made in your httpd.conf file and go to your available services and stop the IIS and run the localhost with out any port numbers... For very detailed explaination follow my first post on this thread...
Regards,
Jerome Dennis D
For phpmyadmin problem kindly go through with these links below
http://bytes.com/topic/php/answers/160028-phpmyadmin-connect-problem
http://www.gidforums.com/t-600.html
http://hintsforums.macworld.com/showthread.php?t=58057
And regarding your PErl Script running on xampp localhost kindly undo whatever change you have made in your httpd.conf file and go to your available services and stop the IIS and run the localhost with out any port numbers... For very detailed explaination follow my first post on this thread...
Regards,
Jerome Dennis D