Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 5th, 2001, 03:26 PM
boxerbay boxerbay is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Miami Florida
Posts: 6 boxerbay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Newbie needs form to post to MYSQL

Hi. Need help creating a Perl script that will post to mysql dbase.
Here's my form: http://www.kellytractor.com/mailer/
I just started the mysql dbase but need to create a table to match the form.
Any help would be greatly appreciated.
Thanks.

Reply With Quote
  #2  
Old June 5th, 2001, 04:45 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Simple enough

Should be pretty easy, you'll need the DBI & DBD mysql modlues

First this should work to create the table

CREATE TABLE catalog (ID INT (11) not null AUTO_INCREMENT, title TEXT not null , business TEXT not null , btype TEXT not null , address TEXT not null , city TEXT not null , state TEXT not null , zip VARCHAR (10) not null , country TEXT not null , telephone VARCHAR (12) not null , ftelephone VARCHAR (12) not null , email TEXT not null , heard TEXT not null , PRIMARY KEY (ID), INDEX (ID), UNIQUE (ID))



Inside the perl program use this to connect to the database:

$dbh = DBI->connect("DBI:mysql:database=DatabaseName;host=LocationOfDatabase","Login","Password", {'RaiseError' => 0}) || NPDie("MySQL error: $DBI::errstr");

It should be obvious where to stick the values required there

At the moment I can't write any more, out of time, but this should be a start for anyone else.

Note, in the database, the address field assumes that you are putting both lines in it...

Reply With Quote
  #3  
Old June 6th, 2001, 12:25 AM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
One way to insert

Try :

#!usr/pathTo/perl

use DBI;


## database config
$host ="xxx.xxx.xxx.xxx";
$database ="data";
$table ="table";
$user ="user";
$mysqlpassword ="password";

$field1="one";
$field2="two";
$field3="three";


## Set Jenni to perfect insert format
$jenni = "insert into $table (field1,field2,field3) values (\"$field1\",\"$field2\",\"$field3\")";


#Choice ONE :

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host","$user","$mysqlpassword",{'RaiseError'=>1});

my $sth = $dbh->prepare("$jenni"); ## go jenni go

if (!$sth) { die "Error:" . $dbh->errstr . "\n"; }
if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; }

$sth->finish;
$dbh->disconnect();


#You do not have to use the prepare with an insert , purists say "prepare" is too slow.

#So Choice Two:

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host","$user","$mysqlpassword",{'RaiseError'=>1});

$dbh->do($jenni);

$dbh->disconnect();

#------------------------------
Also : {'RaiseError'=>1} should be replaced with || die " Could not connect to database so buy Microsoft Shares today";

Too tired to comment on proper code for this error tonight . Sorry.


Note: Open with notepad.exe [text editor] and read " mysql.pm " , at the bottom of this perl module
you will find documentation on the uses and connections to MySql
and example syntax's for these uses.
__________________
Thanks

Foot in Mouth ver 1.2.5 Onion

Reply With Quote
  #4  
Old June 19th, 2001, 02:35 AM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
boxerbay,

the o'reilly book "MySQL & mSQL" ISBN 1-56592-434-7 is superb and will give you everything you need from building the database, tables, indexes right through to perl reference for code creation.

if all you need to do is populate the DB with the mailer details, PHP may be the way forward?

robert.swift.

Reply With Quote
  #5  
Old June 19th, 2001, 07:50 AM
boxerbay boxerbay is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Miami Florida
Posts: 6 boxerbay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Thanks

Thanks Robert I'll check it out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Newbie needs form to post to MYSQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT