|
Author
|
Topic: form data to mysql using Perl ?
|
vbedceo Junior Member
|
posted September 21, 1999 03:04 PM
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
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
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
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'});
|