ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ?
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\")");
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.