LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2010, 07:04 AM   #1
kantu
Member
 
Registered: Sep 2008
Posts: 77

Rep: Reputation: 16
Question CGI MySql HTML Forms


I was trying to get data from html forms and then insert it into sql database
Code:
my $st=param('student');
my $reg=param('regno');
my $marks=param('marks');
.
.
.
my $sth1 = $dbh->prepare('insert into stdb(name,regno,marks) values ('$st','$reg','$marks')');
I am stuck in that insert query , i googled it out and saw on some articles that we can use %FORM{name} etc instead of using $st in my case
But i got errors for that also
Global symbol "%FORM" requires explicit package name
I am new to perl scripting, i tried perldocs and perldoc site also but found it tough to understand, could some one please guide me or suggest a beginner book ?
 
Old 02-26-2010, 10:30 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,699

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by kantu View Post
I was trying to get data from html forms and then insert it into sql database
Code:
my $st=param('student');
my $reg=param('regno');
my $marks=param('marks');
.
.
.
my $sth1 = $dbh->prepare('insert into stdb(name,regno,marks) values ('$st','$reg','$marks')');
I am stuck in that insert query , i googled it out and saw on some articles that we can use %FORM{name} etc instead of using $st in my case
But i got errors for that also
Global symbol "%FORM" requires explicit package name
I am new to perl scripting, i tried perldocs and perldoc site also but found it tough to understand, could some one please guide me or suggest a beginner book ?
So you got errors...how about telling us what the errors were. We can't guess.

But if that's your code, you seem to be missing the part where you open the connection to MySQL, and attach to the database.
Code:
my $dsn = "DBI:mysql:<Database Name Goes Here>";
my $user = "<DB User name, either as string or variable>";
my $pass = "<DB password, either as string or variable>";
$dbh = DBI->connect($dsn, $user, $pass,{ RaiseError => 1})
     or die "Could not connect to database! $DBI::errstr";
And your insert line looks wrong:
Code:
$dbh->do("INSERT INTO <Table Name> values (\"$variable1\",\"$variable2\")");
 
Old 02-26-2010, 11:18 PM   #3
kantu
Member
 
Registered: Sep 2008
Posts: 77

Original Poster
Rep: Reputation: 16
solved

I didnt put the whole code i only put the line where i got stuck ,
instead of having query in dbh->prepare
I had a variable that holds my query ,
$query="INSERT INTO table values('$val1','$val2')";
now dbh->prepare($query)
This worked fine now , iam trying to figure out why it cant be done straight forward as in my first post
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic CGI: 2 forms, 2 submits: HOW? chrism01 Programming 6 02-05-2008 12:12 AM
MySQL results to html forms using PHP xemous Programming 3 08-15-2005 03:27 PM
Forms in HTML J_K9 Programming 5 06-30-2005 02:21 PM
Posting to CGI Forms goldcougar Linux - Newbie 1 07-02-2004 10:13 AM
cgi-bins and fill out forms sachitha Programming 4 03-22-2004 02:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration