★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum4/HTML/000090.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  MySQL
  form data to mysql using Perl ?

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   form data to mysql using Perl ?
vbedceo
Junior Member
posted September 21, 1999 03:04 PM     Click Here to See the Profile for vbedceo   Click Here to Email vbedceo     Edit/Delete Message Reply w/Quote
Could anyone suggest a newbie a good perl cgi script to handle data from a "user registration" html FORM and insert into mysql database?

cybernaut
Junior Member
posted September 21, 1999 04:07 PM     Click Here to See the Profile for cybernaut   Click Here to Email cybernaut     Edit/Delete Message Reply w/Quote
Newbie to Perl or mySQL?

I use both but I find it's easier to use PHP with mySQL for both inputting user submissions (from a form) to a database(s) as well as displaying the output, emailing it out, or using in neat ways like creating hyperlinks from certain values, etc.

There are several tutorials on this site and hotwired.com (webmonkey) that walk a newbie through it... to have you up and running in no time.

I have not come across any stand-alone scripts in Perl to do this. I mostly end up doing them from scratch.

vbedceo
Junior Member
posted September 21, 1999 05:27 PM     Click Here to See the Profile for vbedceo   Click Here to Email vbedceo     Edit/Delete Message Reply w/Quote
Actually I am looking for just a guideline to get started on how to pass info from a FORM using perl and keep data in mysql. For ex;
if I have just 2 INPUTs (type=text)one is name and another is email. When ACTION=/old?u=http%3A%2F%2Fwww.devshed.com%2FTalk%2FForums%2FForum4%2FHTML%2Fmyperl.cgi%2C&y=1999 what does it look like in myperl.cgi?

use DBI;
print "Content-type: text/html\n\n"; $user = "myuserid";
$database = "mydatabase";
$host = "";
$port= "3333";
$password = "mypasswd";
$driver = "mysql";
$table = "test";
$dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
$dbh = DBI->connect($dsn, $user, $password);
*****HERE IS MY NEWBIE QUESTION********
$name = ???
$email = ???
*****END MY QUESTION***********

$sth = $dbh->prepare("INSERT INTO $table VALUES($name, $email)");

Thanks for your time.

moderator
Administrator
posted September 23, 1999 10:38 AM     Click Here to See the Profile for moderator   Click Here to Email moderator     Edit/Delete Message Reply w/Quote
This should work if your form's method=get:
code:

$temp=$ENV{'QUERY_STRING'};
@pairs=split /&/,$temp;
foreach $item(@pairs) {
($key, $content)=split /=/,$item,2;
$content=~tr/?/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}

$name=$fields{'name'};
$email=$fields{'email'};


If your form's method=post you need to replace the first line with:

code:

read(STDIN,$temp,$ENV{'CONTENT_LENGHT'});

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.