|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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... |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
Thanks Robert I'll check it out.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Newbie needs form to post to MYSQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|