Sponsored Content
Top Forums Programming Problems using Perl DBI to edit database entries - basic stuff Post 302368891 by Dave247 on Friday 6th of November 2009 12:04:17 AM
Old 11-06-2009
Problems using Perl DBI to edit database entries - basic stuff

Hello. I am taking a Perl class in college and we've briefly covered SQL and moved on. We have a term project and we can do whatever we want. My project will rely strongly on an SQL Database so I am trying to learn as much about Perl DBI as I can to get things up and going.

I am basically making CGI scripts that take user input from forms and then put that into database tables so I will need to be able to search, edit, insert and delete data entries. I am essentially having trouble getting on my feet with how to manipulate data in my database.

My instructor set up a database for me which I can access and edit but I am already having trouble with my script. I am hoping that someone can help me figure out what things I need to include in my code to get this working.

So far, I have a CGI script that takes a few fields of form data from a webpage: username, email, and password. I am attempting to put this into an SQL table called "user_accounts" and this table has three colomns named "username", "password", and "email".

Here is my Perl code with the DBI code in there to access the database:
Code:
#!/usr/local/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

print header;
print start_html;
use DBI;

#FROM FORM
$NewUserName=param('NewUserName');
$NewEmail=param('NewEmail');
$Password=param('Password');
$CryptPassword=crypt("$Password","CS");

#SQL CODE

$dbh = DBI->connect("DBI:mysql:daveDB","dave","pass412");
$sth = $dbh->prepare($sql);
$res = $sth->execute();
$dbh = ("INSERT INTO user_accounts (username, email, password)
VALUES ($NewUserName, $NewEmail, $CryptPassword)");
$sth->finish();
$dbh->disconnect();

print end_html;

When I run this, I get this error message: "Can't locate object method "disconnect" via package "INSERT INTO user_accounts (username, email, password)"

I have googled this error message and I have edited my code a little here and there and gotten a few different errors which I do not fully understand or know how to fix. I have read over the pages of my textbook that cover DBI and I have looked at Oreilly's Perl DBI book and I have googled countless times and I just cant figure out how to simply make some lines of code that access and edit my SQL database. I really need some help so I can get things functioning for my project as I am going to eventually run out of time.

Any help is very appreciated
Dave247
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problems Downloading and Installing Stuff

HI to everyone, I have been for a very long time in my life a GUI user, and now that i have to use a Solaris 5 terminal, i am not sure how to do some things: Downloading stuff from the internet: How do i do that? in a GUI you just click on the link and start downloading automatic, but i have... (4 Replies)
Discussion started by: sx3v1l_1n51de
4 Replies

2. Shell Programming and Scripting

PERL DBI module install

We ran into an issue trying to install DBI and DB2 modules for perl for AIX from the link http://www-306.ibm.com/software/data/db2/perl/ We tried to install the DBI module using bash# perl -MCPAN -e 'install DBI' command. However we ended up with the following error. Stop. ... (3 Replies)
Discussion started by: jerardfjay
3 Replies

3. UNIX for Dummies Questions & Answers

SSH Connection - Problems viewing stuff

Hey, I connected with Cygwin and this command: "ssh -Y USER@web.com" Then trying to open a program, but this error appeared: "Cannot open X display: DISPLAY variable unset" what do I have to do? Thanks. Alex (3 Replies)
Discussion started by: alf123
3 Replies

4. Programming

perl dbi to oracle getting disconnect_all for oracle dbi help

hi i am trying to connect to an oracle database using dbi and i get this :: Driver has not implemented the disconnect_all method. at /opt/perl/lib/site_perl/5.8.0/sun4-solaris/DBI.pm line 575 END failed--call queue aborted. for all i know, the script was working earlier, but has... (1 Reply)
Discussion started by: poggendroff
1 Replies

5. Shell Programming and Scripting

Installing Perl DBI and DBD

Hi, i have some queries on installing the Perl DBI and the DBD Oracle. I know that i have to install the DBI first. I have the source files in a folder in my home directory.The commands to install arecd /home/DBI Perl Makefile.PL make make installI would like to know, after executing these... (4 Replies)
Discussion started by: new2ss
4 Replies

6. Shell Programming and Scripting

DBI - Change database

Hello ! I am working on a small Perl script that should connect to the MySQL server, will select all the databases one by one and do some queryes on each. I started working on it but I just saw that on the DBI manual page there's no method for changing the working database. Am I missing... (2 Replies)
Discussion started by: Sergiu-IT
2 Replies

7. Shell Programming and Scripting

connect to MySQL from Perl using DBI

Hi, I want to connect perl with the mysql to select and so on but the connection don't work code #!/usr/bin/perl BEGIN { # PERL MODULES WE WILL BE USING use DBI; $dbh = DBI->connect('DBI:mysql:C:\Program Files\MySQL\MySQL Server 5.0\data\db1','','pass') or die $DBI::errstr;} #... (1 Reply)
Discussion started by: eng_shimaa
1 Replies

8. Shell Programming and Scripting

perl: help with DBI

Hi there, I have a bit of code similar to below (which ive actually got from perldoc, but mine is similar enough) $sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region }); $sth->execute; my ($region, $sales); # Bind Perl variables to columns: $rv =... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

9. Shell Programming and Scripting

GNU-Screen Stuff problems

OPTIONS="java -Xms1024M -Xmx1024M -jar craftbukkit.jar" PROCESS=server01 screen -dmS $PROCESS $OPTIONS nogui # Starting the application screen -x $PROCESS -X stuff `printf "stop\r"` # Closing the application screen -x $PROCESS # Attaching to the... (3 Replies)
Discussion started by: Zanax
3 Replies

10. Shell Programming and Scripting

Perl DBI error

Hi All, I installed DBI module in a non INC location and using it in my script via "use lib". But it throw the below error at the "use DBI" step. Please help Usage: DBI::_install_method(dbi_class, meth_name, file, attribs=Nullsv) at /xx/xxx/xxxxx/xxxxx/oracle/lib/DBI.pm/oracle/lib/DBI.pm line... (2 Replies)
Discussion started by: prasperl
2 Replies
Catalyst::Model::DBI(3pm)				User Contributed Perl Documentation				 Catalyst::Model::DBI(3pm)

NAME
Catalyst::Model::DBI - DBI Model Class SYNOPSIS
# use the helper create model DBI DBI dsn username password # lib/MyApp/Model/DBI.pm package MyApp::Model::DBI; use base 'Catalyst::Model::DBI'; __PACKAGE__->config( dsn => 'dbi:Pg:dbname=myapp', password => '', username => 'postgres', options => { AutoCommit => 1 }, ); 1; my $dbh = $c->model('DBI')->dbh; #do something with $dbh ... DESCRIPTION
This is the "DBI" model class. METHODS
new Initializes DBI connection $self->dbh Returns the current database handle. $self->stay_connected Returns a connected database handle. $self->connected Returns true if the database handle is active and pingable. $self->connect Connects to the database and returns the handle. $self->disconnect Executes rollback if AutoCommit is active, disconnects and unsets the database handle. SEE ALSO
Catalyst, DBI AUTHOR
Alex Pavlovic, "alex.pavlovic@taskforce-1.com" COPYRIGHT
Copyright (c) 2005 - 2009 the Catalyst::Model::DBI "AUTHOR" as listed above. LICENSE
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2010-01-28 Catalyst::Model::DBI(3pm)
All times are GMT -4. The time now is 10:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy