1

Here is my perl code located in /perl-bin/ directory but for some reason when i try to get something from MySQL i keep getting Error 500

here is the code

#! /usr/bin/perl

 use warnings;
 use strict;

 print "Content-type: text/html\n\n";
 print "<!DOCTYPE html>\n";
 print "<html>\n";
 print "<head>\n";

 print "<title>00000000000000000000</title>";
 print "<link rel='stylesheet' type='text/css' href='style.css' />";

 print "</head>\n";
 print "<body>\n";

 print "<div id='top'></div>";
 print "<div id='header'>";
 print "<div id='logo'></div>";

 print "</div>";

 use Mysql;

# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "000_ooo";
$tablename = "users";
$user = "000_root";
$pw = "l00V0r009;00XE_%0q;U00000000000000";

# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);

# SELECT DB
$connect->selectdb($database);

# DEFINE A MySQL QUERY
$myquery = "SELECT * FROM $tablename";

# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);

# HTML TABLE
print "<table border='1'><tr>
<th>id</th>
<th>product</th>
<th>quantity</th></tr>";

# FETCHROW ARRAY

while (@results = $execute->fetchrow()) {
    print "<tr><td>"
    .$results[0]."</td><td>"
    .$results[1]."</td><td>"
    .$results[2]."</td></tr>";
}

print "</table>";

 print "</body>\n";
 print "</html>\n";
4
  • 6
    Have you tried looking in your webserver's error log? Have you tried running it from the command line? Commented Oct 26, 2011 at 4:49
  • i have no access to command line, and i dont see any logs Commented Oct 26, 2011 at 4:58
  • 6
    Then refuse to do any more work until your client or manager give you a reasonable working environment :-) Commented Oct 26, 2011 at 10:24
  • 1
    @PT Desu, If you don't have access to your logs, we definitely don't. Commented Oct 26, 2011 at 18:34

3 Answers 3

8

You can try using CGI::Carp to get an error message in your browser:

use CGI::Carp qw(fatalsToBrowser);

(Don't leave this in after debugging unless you want your users to see cryptic error messages that might reveal confidential information.)

Are you sure the Mysql module is the right way to access the database? That module is obsolete; everybody uses DBI these days (possibly with another layer on top). You might try a Hello World type script that just does use Mysql; but doesn't attempt to actually connect to the database, to see if it's even installed.

Sign up to request clarification or add additional context in comments.

Comments

5

A simple syntax check reveals the problem.

$ perl -c mysql
Global symbol "$host" requires explicit package name at mysql line 26.
Global symbol "$database" requires explicit package name at mysql line 27.
Global symbol "$tablename" requires explicit package name at mysql line 28.
Global symbol "$user" requires explicit package name at mysql line 29.
Global symbol "$pw" requires explicit package name at mysql line 30.
Global symbol "$connect" requires explicit package name at mysql line 33.
Global symbol "$host" requires explicit package name at mysql line 33.
Global symbol "$database" requires explicit package name at mysql line 33.
Global symbol "$user" requires explicit package name at mysql line 33.
Global symbol "$pw" requires explicit package name at mysql line 33.
Global symbol "$connect" requires explicit package name at mysql line 36.
Global symbol "$database" requires explicit package name at mysql line 36.
Global symbol "$myquery" requires explicit package name at mysql line 39.
Global symbol "$tablename" requires explicit package name at mysql line 39.
Global symbol "$execute" requires explicit package name at mysql line 42.
Global symbol "$connect" requires explicit package name at mysql line 42.
Global symbol "$myquery" requires explicit package name at mysql line 42.
Global symbol "@results" requires explicit package name at mysql line 52.
Global symbol "$execute" requires explicit package name at mysql line 52.
Global symbol "@results" requires explicit package name at mysql line 54.
Global symbol "@results" requires explicit package name at mysql line 55.
Global symbol "@results" requires explicit package name at mysql line 56.
mysql had compilation errors.

Your program includes use strict (as it should). But you haven't declared any of your variables.

2 Comments

it wont work even if i remove use strict, while i seem to have all needed modules, DBD::Pg (2.18.1), DBD::SQLite (1.31), DBD::SQLite2 (0.33), DBD::mysql (4.019), DBI (1.616)
Don't remove strict. Fix the problem by declaring the variables. What is that list of required modules? You don't use any of those modules. You use Mysql.pm. It looks like Mysql.pm used to be part of the DBD::mysql distribution but it was removed about five years ago. This program is not going to work until you change it to work with DBI and DBD::mysql.
1

I agree agree with @cjm. You should definitely be using the DBI module at a minimum. Also, for aesthetics, its best to keep all of your 'use' statements at the top of your code, prior to any other code.

One other thing I would make sure of is that the username and password you are using actually work. Try logging into mysql via the command line, if they do, connect to the db and also ensure the table exists. Take those variables out of the equation as well.

1 Comment

all mysql related information is correct, its been tested via PHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.