in reply to Dealing with uninitialized values

First off use placeholders. Especially when getting data from CGI. Else you are wide open to a SQL Injection attack. It also handles quoting correctly.
# Put question mark here for your placeholder my $sql = "SELECT * FROM users WHERE id = ?"; my $statement = $db_handle->prepare($sql) or die "Couldn't prepare query '$sql': $DBI::errstr\n"; # Put your $scalar here to be interpolated $statement->execute($user) or die "Couldn't execute query '$sql': $DBI::errstr\n";
As to your error - Have you checked the DB to see what's really in there. Your retrieval and deref look fine. So I'm guessing your data says 'UsernameDBI::db=HASH(0x838242c)' and you forgot to deref something when you inserted the data.


grep
One dead unjugged rabbit fish later

Replies are listed 'Best First'.
Re^2: Dealing with uninitialized values
by driver8 (Scribe) on Oct 14, 2006 at 09:39 UTC

    grep, the "DBI::db=HASH(0x838242c)" I think is the result of DBI->connect("dbi:mysql:database=test;host=localhost;user=root;") being printed.

    shalomgod, I would change the code like this to fix your error:
    my $user = '1'; #or whatever default value you want print $query->header("text/html"), $query->start_html(-title => "Database Test"), $query->h1("Database Test"), $user = $query->param("username"), my $db_handle = DBI->connect("dbi:mysql:database=test;host=localhost; +user=root;") or die "Couldn't connect to database: $DBI::errstr\n";
    I would also definitely recommend using placeholders, like grep said, and taint checking as well. I'd recommend checking out Ovid's CGI course at http://users.easystreet.com/ovid/cgi_course/, most importantly Lesson 3 on security.