LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-01-2002, 01:56 AM   #1
robrecc
Member
 
Registered: Feb 2002
Posts: 50

Rep: Reputation: 15
Add.pl View.pl problems


Hello everybody

What im trying to do just to start is have a page that i can add entries to a mysql database from a perl script-

add.pl is the script i use for this

#!/usr/bin/perl -w



use CGI;
use DBI;

print CGI::header();


my $username = dbquote(CGI:aram('name'));
my $email = dbquote(CGI:aram('email'));

unless ($username) {
print <<PAGE;
<h1>Add a Subscriber</h1>
<form action=add.pl method=post>
Name: <input type=text name=name><br>
Email: <input type=text name=email><br>
<input type=submit value="Add Subscriber">
</form>
PAGE

exit;
}

###### CONNECT TO DATABASE #################

my $dbh = DBI->connect("dbi:mysql:shoes:localhost:3306", "user", "pass");

####### PREPARE QUERY #######################

my $sth = $dbh->prepare("insert into subscribers(username, emailaddr)
values('$username', '$email')");

######## EXECUTE QUERY #####################
$sth->execute();


print <<PAGE;
<h1>User Added</h1>
The user $username was just added. Want to <a href=add.pl>add
another</a>?
PAGE

sub dbquote {
my($str) = @_;

$str =~ s/"/\\"/g;
$str =~ s/\\/\\\\/g;
$str =~ s/'/\\'/g;

}


my view.pl file seems to work fine

#!/usr/bin/perl -w

use DBI;
use CGI;

print CGI::header();

print "<h1>Subscribers</h1>";

#connect

my $dbh = DBI->connect("dbi:mysql:shoes:localhost:3306", "root", "sundin_13");

#prepare query

my $sth = $dbh->prepare("select username, emailaddr from subscibers");

#execute query

$sth->eecute();

while(my ($username, $email) = $sth->fetchrow_array()) {
print "$username: $email<br>\n";
}


My problem is when i type in values in the boxes and click add subscriber the script seems to run no errors but no entry in the database get added. I should see the resultswith view.pl and as well manually going in to mysql but i dont


im am stuck at this point any help is greatly appreciate

Thank you
Robert
 
Old 02-08-2002, 05:35 PM   #2
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 31
Test your return values. You should test the return values for all the DBI functions to see which one failed. At any rate your final code should have those test in there as well.

a lot of the time, it's the "connect". Mysql is particular about priviledges. You have to have a "user@%" or a "user@localhost" with access to the database you're loading. Test the user's access by 'mysql -p pass -u user' on the box, and try the 'use database' command if you get in
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with Diamond View Monitor Alighment 47.46.45 Linux - Hardware 1 06-28-2005 11:53 AM
W2K cannot view samba share but can view NT FiveFlat Linux - Software 3 06-10-2005 02:54 PM
Problems w/ manually add. a driver at install. time Toshi3 Linux - General 0 09-13-2004 11:35 PM
Problems to view files on Win2k Machine jazzyjazz Linux - Networking 1 10-31-2003 02:03 PM
Add user problems mrsolo Linux - Software 3 01-21-2003 02:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration