Gossamer Forum
Home : General : Perl Programming :

Perl Forum Submission

Quote Reply
Perl Forum Submission
I need to write a Perl script for a cgi-bin directory that sends the values from a 7-field HTML form to a mySQL database.

Any suggestions on where I can find material to help me with this? So far, on-line manuals I'm found aren't very helpful. They all say how "easy" mySQL is, but I find it very confusing.


Quote Reply
Re: Perl Forum Submission In reply to
If you find it very confusing then I wouldn't suggest you write such a script.

Try
www.perl.com
www.mysql.com

Eliot also provided some code you will find useful which you will find if you search the forums.

Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: Perl Forum Submission In reply to
I think all I need is to see a "completed" Perl script that works. I could then adapt it to fit my needs, as I do have some programming abilities.

All the examples I've found so far are "snippets" of code. I need to see the entire script.

For example, I found this code:

------------------

$dbh = DBI->connect("DBI:mysql:databasename:mysql.server.net","login","password");

mysql_select_db (databasename);

$result = mysql_query ("INSERT INTO databasename (column1, column2, column3, column4, column5, column6, column7)
VALUES ('$Name', '$Addr', '$City', '$State', '$ZIP', '$Cable', '$Comments')");
if(!$result)
{
echo "<b>Something not added:</b> ", mysql_error();
exit;
}
if($result)
{
mysql_close($db);
## print "Something added sucessfully!";
}

--------------------

But how do I IMPLEMENT it? How does the FORM interact with this? etc....


Quote Reply
Re: Perl Forum Submission In reply to
You need to add that code into your script then you need to add something like.....

$Name = $FORM{Name};
$Addr = $FORM{Address};
$City = $FORM{City};

...and code to parse the form.

etc.......

Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: Perl Forum Submission In reply to
And also need to add the required modules at the top of the script, like:

Code:

use CGI();
use DBI;


etc., etc., etc.

Regards,

Eliot Lee
Quote Reply
Re: Perl Forum Submission In reply to
In Reply To:
Any suggestions on where I can find material to help me with this? So far, on-line manuals I'm found aren't very helpful. They all say how "easy" mySQL is, but I find it very confusing.
Yes, if you have any understanding of Relational Database Models and SQL statements, then yes, MySQL is very easy...compared to flat file database systems. If you don't have any of the above stated knowledge, then, yes, it is confusing.

Simply knowing "Perl" or programming is only piece of the pie.

Regards,

Eliot Lee
Quote Reply
Re: Perl Forum Submission In reply to
May I suggest PHP? It feels as if it was written to use with mySQL. PHP is much easier and faster to learn than Perl. The book "PHP Essentials" by Julie Meloni will have you writing code within an hour. The book is full of examples.

Brief outline of events:

* Create webpage with form (method=get)
* PERL - Parse query string (look at dbman code) and split into name/value pairs
* PHP - name/value pairs are present - no work to perform
* Open mySQL connection
* mySQL query to insert values

NOTE: You can use post method also, but for PERL you have to pull out of $ENV. With PHP there is no difference to the method.

An example of the pairs are present in PHP:
Your form has two input boxes name=user and name=email. When PHP starts you can access them with $user and $email. The values are in the variable. Slick, yea!

I was considering using Perl to write to mySQL, but when I saw PHP, I switched. It is so quick you figure something has to be wrong. With the time savings you can learn how to do it in Perl. ;)

Quote Reply
Re: Perl Forum Submission In reply to
Does there need to be some server configuration to be able to use PHP?

----

Here's where I'm at in my Perl adventure: (of course, it doesn't work, which is why I'm posting it here, with sensitve data--such as userid and passwords--'xxx'ed out):

#!/usr/bin/perl

use CGI();
use DBI;
$dbh = DBI->connect("DBI:mysql:xxx:apus.valueweb.net","xxx","xxx");

# Parse input form data

&parse_form(\%DATA);

# If env_report is not empty, save/send those too

if ($DATA{'param_env_report'}) {
$DATA{'param_env_report'} =~ s/\s//g;
@ENV = split(/\,/,$DATA{'param_env_report'});
foreach (@ENV) {
$DATA{$_} = $ENV{$_};
}
}

$Name = $DATA{Name};
$Addr = $DATA{Addr};
$City = $DATA{City};
$State = $DATA{State};
$ZIP = $DATA{ZIP};
$Cable = $DATA{Cable};
$Comments = $DATA{Comments};

mysql_select_db (xxx);

$result = mysql_query ("INSERT INTO cabletheft (column1, column2, column3, column4, column5, column6, column7)
VALUES ('$Name', '$Addr', '$City', '$State', '$ZIP', '$Cable', '$Comments')");
if(!$result)
{
echo "<b>Something not added:</b> ", mysql_error();
exit;
}
if($result)
{
mysql_close($db);
print "Something added sucessfully!";
}


Quote Reply
Re: Perl Forum Submission In reply to
Er, you're mixing Perl with PHP syntax there. Hop over to devshed.com and read through their tutorials for Perl, and Mysql, to see about what you need for syntax.

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Perl Forum Submission In reply to
In Reply To:
Does there need to be some server configuration to be able to use PHP?
Your webhost should have it installed already. Most do. If yours does not you should ask them to install it, either that or move to another host. PHP is Open Source, like Perl, ?nix, Apache. As such it is low/no cost. I've never installed it but from what I've read it is easy.

The book "PHP Essentials" by Julie Meloni devotes a chapter or two on installing Apache, PHP and MySQL on your own PC. The source code for her examples is also available for copying/downloading at her website: http://www.thickbook.com. And really, you can start writing good PHP within minutes of starting her book.

Sounds like your new to this game and need to start buying some reference texts. May I suggest http://www.bookpool.com. Saw this link here a few months ago. I have ordered from them 4 times in last 2 months. Their prices are considerably lower than anyone elses. They specialize in and stock computer/tech books, no NYTimes Bestsellers. Cool

Quote Reply
Re: Perl Forum Submission In reply to
Are you getting commission for plugging all these books or what?


Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: Perl Forum Submission In reply to
In Reply To:
Are you getting commission for plugging all these books or what?

Looks like you are spamming to me.
It's obvious you are unclear as to the definition of spamming. As to getting a commission, it seems you are running your mouth rather that checking the facts. Bookpool has no affiliates or commissions, merely great prices on the resources we all need.

In Reply To:
If you find it very confusing then I wouldn't suggest you write such a script.

Try
www.perl.com
www.mysql.com
Great advice coming from a veteran. It's obvious that jjo is new to the game. He's new to this forum based on his registration date. Discouraging replies, like yours above are far worse than my reiterating a point. They are condescending.

When I request info from a forum it's because I have already been to the sources, but need advice from someone who's been there and done that. Perhaps I am assuming jjo has already done the same. The sources you cited are great and can provide all the answers, if you know how to search for what you need, when you don't know what it is you need!

What I offered jjo was practical information about a source that has served me well. Where, or if, he buys any book is no concern of mine. I responded in the spirit of helping someone who is in need.

When someone takes the time to submit a problem, if you can't offer some practical advice, why do you respond? Very few programmers wake up in the morning and decide to write something they are not equipped to handle. They generally come about because of job demands and employer expectations.

We as programmers have to pay our dues and learn our craft. When we can, we need to offer assistance to those starting out. If for no other reason, then to perpetuate the cycle that started back when we first asked for help. These are concepts I learned back when I first started programming in Fortran in the 60's.

I am not trying to start a flame war with you Paul. But your replies are of some dubious value, as is this reply. Wink

Cheers
Randy

Quote Reply
Re: Perl Forum Submission In reply to
In Reply To:
Discouraging replies, like yours above are far worse than my reiterating a point. They are condescending.
So providing links to the most comprehensive resources for perl and mysql is discouraging?



Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: Perl Forum Submission In reply to
In Reply To:
If you find it very confusing then I wouldn't suggest you write such a script.
I have read alot of your replies and they are usually quite helpful and very informative. Your quote above is not up to your usual high standards.

Cheers

Quote Reply
Re: Perl Forum Submission In reply to
It was not meant to be patronising or condescending. If you don't know how to make a certain script or don't feel confident making it then you shouldn't....do you not agree?

Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: Perl Forum Submission In reply to
No! I do not agree. I have surprised myself and others countless times by undertaking an impossible programming task. I learned as I tried. Back in the early days of computers there were very few teachers and even fewer texts! We discovered new techniques as we undertook new challenges. That's how most software was written, especially operating systems.

Everyone of us is born ignorant. By questioning, trying, and learning we acquire knowledge and reach our potential. When I was young my Dad's favorite reply to any question was "look it up". He was not a teacher. The librarian showed me where to look and how to look it up. My teachers answered the questions that still remained. They helped me expand upon my new found skills.

Cheers

Quote Reply
Re: Perl Forum Submission In reply to
You have just contradicted yourself because you had a go at me for telling that other user to look at perl.com and mysql.com but then you just said.....

In Reply To:
When I was young my Dad's favorite reply to any question was "look it up".
Paul Wilson.
http://www.wiredon.net/gt/
www.perlmad.com(Soon)
Quote Reply
Re: Perl Forum Submission In reply to
I never said his approach was right. In words even you can understand: I said "He was not a teacher"! I have a feeling you are just trying to be argumentative. Your tone supports my opinion that you were not trying to be helpful, merely condescending.

It doesn't take any brains to tell someone to go to PerlDocs, etc. Be better than that - be a teacher. When Alex comes on the board he doesn't tell people to look it up. He provides assistance. That's why most people come to this forum - they need assistance. They don't need someone to tell them to go someplace else.

Quote Reply
Re: Perl Forum Submission In reply to
I am not being argumentative in the slightest...you seem to be the one who is making personal remarks...

In Reply To:
In words even you can understand:
Maybe Alex provides all the answers because he is the author of the script and knows more about perl/cgi/mysql than any of us.

If you *are* a programmer then why don't you answer the questions instead of telling people to go and read books by "Julie".Mad

Pot calling the kettle black....understand??

This is the last post I will make in this thread.

Paul Wilson.
http://www.wiredon.net/gt/
Coming soon => www.perlmad.com
Quote Reply
Re: Perl Forum Submission In reply to
Paul,

The reference to a specific book was to point the user in a specific direction where he could find answers. Why duplicate what he could learn from the clear examples in the book. Things that are difficult to find at PerlDocs, etc. You would have been more helpful directing the user to a specific page at PerlDocs.

One would get the impression you were most offended by "Julie". Sounds sexist to me. But since it is late in England, I must assume you are tired and cranky. Your responses in this thread are not up to your usual standards.

Be a mentor - not an elitist.

Cheers,
Randy

Quote Reply
Re: Perl Forum Submission In reply to
Not taking sides here but wouldn't you agree, Rand, that you are a better coder from having to dig for the answers?
I think it's one thing to offer examples when there is an uncharted area so to speak; it's us against the unknown.
But it's another thing entirely when someone is asking how to use the print statement or split a string.
People do need to work for knowledge by showing that they care enough to learn the basics.
I'm not saying that this thread is an example of that but in regards to your statements about 'elitest responses',
'perldoc -f split' is a valid response to someone who is either a) unaware of the great documentation they have available, or b) too lazy to learn basic command syntax.

I've learned what I know from busting my butt to learn the basics and discussing more advanced techniques with other developers.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Perl Forum Submission In reply to
Yup. Digging thru docs and stuff is THE best way to learn. People that won't take the time to do that but want someone else to just give the answer, are basically saying that their time is far more important then the person giving the response.

Not that I think anyone in this thread is like that, im just adding to the RTFM discussion Smile

Learning from other developers when working with them is phenomenal too. I think myself and G were both able to learn a ton from each other with the year we spent at our last job together. Was a very valuable experience. To that end, work with other people and go to user groups. It is a hell of an experience.

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Perl Forum Submission In reply to
I agree absolutely. The more one digs, the more one learns, and the better one becomes at learning more. That is what separates the professional from the amateur. I have seen some questions where it was obvious the poster did not even know the basics and had spent no time trying to learn. They deserve to get lambasted and given a surly "see PerlDocs". Whether they would deserve a term like split would be the repliers option! :)

Others pose questions that deserve a proper answer. I have had mixed results trying to find an answer at Perl.com, PHP.com, CPAN, etc. Amidst all the documentation the answer awaits. Trying to find it can sometimes be very frustrating.

The most frustrating thing I have encountered is knowing I need some information, but not knowing the keyword that leads to the answer. Listing a topic or page within a URL, or even the term 'split', helps the questioner zero in on the answer quicker. The threads in this forum are riddled with snappy one-liners like "see PerlDocs, etc.". Granted some of those replies are warranted.

I wasn't trying to flame Paul at first. I took exception to his accusing me of spamming (he has since deleted that portion from his original post) and getting a commission because I recommended a book and source.

I was offering another source of information. I could have, like Paul said in his last reply, laid out more detailed help. But the user at that time didn't know if he had PHP available.

The statements:

"If you find it very confusing then I wouldn't suggest you write such a script."

and

"If you don't know how to make a certain script or don't feel confident making it then you shouldn't....do you not agree?"

exhibit a very disturbing attitude for someone offering help. It is this attitude that seems condescending and elitist.

Paul has over 1400 posts listed. How many have been to go somewhere else for help? I don't know Alex, but from reading his replies, I don't feel like this is the type of help he intended others to offer. If he did, he could just eliminate this "Perl, CGI, SQL and more!" section completely, save his bandwidth, and put up a page saying "go see PerlDocs, etc."

From just going through an extensive 6 month period trying to get up to speed on several of the newer languages, I can appreciate how an elementary concept can be difficult to understand at first. A newbe and vet discussing those elements allows one to get clarification and another point of view. That is the purpose of a forum, IMHO.

I appreciate your point of view and discussion of this matter.

By the way, your signature:
s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
is very clever.

Randy


Quote Reply
Re: Perl Forum Submission In reply to
I would agree that "goto cpan, perldocs, etc is not neccessarily helpful.

If you are new to Perl, msSQL, php etc, part of the problem can be you don't know what you are looking for. To be more precise, I don't always know the correct phrase to search for when I am at these other sites.

A usefeul and helpful reply like goto to perldocs and search for "global array" would be a way of providing someone a way to find the knowledge they need.

Quote Reply
Re: Perl Forum Submission In reply to
Yes, if you do not know which keyword you're looking for (split etc) then a pointer is welcome. My technique for this would be the answer:

perldoc -f split

as that points to where in the docs to go, and is a hint of what exactly is needed. A simple "go read the docs" is NOT a good answer. So I agree... pointing to the docs is the way to go, but a hint of WHERE to look is appropriate.

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.