Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL form handling

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am new to MySQL and need a bit of advice regarding form handling. Are there any tutorials around which deal with this aspect of PERL/MySQL? All the tutorials and books I have read deal with the specific function of each command rather than advice on how all the various bits are 'bolted' together.

Keith
 
Do you want to parse a form and insert the fields into a database?

Your question is not clear enough so we can give a clear answer.

To work with mysql you need two modules to install for perl.

DBI
DBD::mysql

once you install these modules and study the documentation of DBI, you can make any query to a mysql db and insert into it or select from it, whatever you like.

To parse an html form with perl the best way is to use CGI which is another module for handling html with perl.

Again the CGI documentation will give you almost all the answers to your questions regarding the use of it.


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Sorry,I'll expand on my initial request.
I have set up a script which controls three seperate tables within a database. The script is array driven and I can read, write and edit any of the 3 tables with the same script.
I wrote a routine which populates all three tables with useful data and the sections for reading the data are all but complete.
I am now trying to work out how to write a new record to a table or write an edited record back to a table.
I understand how to do the actual writing but it is the manipulation of the data which I would like some help with.
Some of the data comes from a parsed form which I am able to access via DBI using '$query->param' etc. but the rest of the data is created within the script at the time of writing, such data as data created, date last edited, username, password etc.
I created the 'INSERT' string programatically for my auto populate routine and will follow the same path with the working table. I would like to ee a working example of such code to ensure I am not missing out on a simple process.
None of the books I have read actually cover this aspect of the programming process.
I will post the code I use to populate the tables if you think I am looking for a free solution.

Keith
 
> I created the 'INSERT' string programatically for my
> auto populate routine and will follow the same path
> with the working table.

Yes, INSERT is the usual way to add new records. For modifying existing records, UPDATE is more what you want, something along these lines:

my $q = $handle->prepare('UPDATE $table SET val1 = ? WHERE idfield = ?');
$q->execute($val1, $id);

You might, depending on what you're doing, want to look at Class::DBI

The book I used for learning this stuff is SQL in a Nutshell, but it is the sort of book that, as you put it, deals with the specific function of each command, so if you are looking for something more tutorialish, it's really not that, although it does have a reasonably good introduction. I got it because it covers four different SQL implementations, and I didn't want to be tied down to one, but if you're strictly interested in MySQL you might find another book better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top