Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Newbie: My database cgi works but gives me weird output

Newbie: My database cgi works but gives me weird output

Newbie: My database cgi works but gives me weird output

#!/usr/bin/perl -w

use CGI;
use strict;
use DBI;

my $hello ="hello";

my $query = new CGI->new();

print $query->header("text/html"),

    $query->start_html(-title => "Database Test"),

 $query->p("Database Test"),

my  $db_handle = DBI->connect("dbi:mysql:database=Test;host=localhost;user=root;")
    or die;
my $sql = "SELECT * FROM users WHERE id = 2";
my $statement = $db_handle->prepare($sql)
    or die;

    or die;
while (my $row_ref = $statement->fetchrow_hashref())
    my $holder = $row_ref->{email};
    print $holder;



Basically I get the correct output which is an email address. But i also get an unwanted hashcode..


I get no compile errors  or anything so im wondering why DBI is getting printed out...

Maybe it has something to do with the fetch_row method?

Any help is much appreciated.

RE: Newbie: My database cgi works but gives me weird output

Because you are treating the hashref->{} like an array() which is incorrect.  Do it this way.


$statement->execute() or die;
my $row_ref = $statement->fetchrow_hashref()

print $row_ref->{email};

M. Brooks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close