Forum Moderators: coopster & phranque

Message Too Old, No Replies

Net::MySQL

How to insert variables values?

         

diogonunes

10:29 am on Dec 28, 2004 (gmt 0)

10+ Year Member



Hi everyone... IŽm having kindŽa problem... IŽm using Net::MySQL to insert data into a DB. HereŽs the deal... when I use the syntax to insert values and I pass, as params the fixed values... it works fine... e.g.:
insert into process (column1, column2) values ("Test1", "Test2");
It works ok...
But when I try to use CGI library to get the input data from a textfield, put the values into variables, and try to record these variables values into the DB, it doesnŽt work... My script is right below... I apreciate help... thanks for all...
#!/usr/bin/perl
use CGI qw/:standard/;
use Net::MySQL;
print header,
start_html('Process Registration'),
h1('Process Registration'),
start_form,
"Process #: ",textfield('processo'),br,
"Process Type: [1-2]",textfield('tipo'),br,
"Lawyer: ",textfield('nome'),br,
"Email: ",textfield('email'),br,
submit,
end_form,
hr,
$process =param('process');
$lawyer =param('name');
$email =param('email');
$type =param('type');

my $mysql = Net::MySQL->new(
database => 'db',
user => 'user',
password => 'pass'
);

$mysql->query(q{
INSERT INTO processo (process, name, email, type) VALUES ($process,$lawyer, $email, $type)
});

rocknbil

5:18 pm on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not familiar with these modules at all but here's a couple things to look at:

my $mysql = Net::MySQL->new(
database => 'db',
user => 'user',
password => 'pass'
);

What is happening here? Is this supposed to be the database name, user name, and password for connecting to an logging into the database or just for example? If it is, then it should be

my $mysql = Net::MySQL->new(
database => 'actual_db_name',
user => 'database_user_name',
password => 'this_user_password'
);


$mysql->query(q{
INSERT INTO processo (process, name, email, type) VALUES ($process,$lawyer, $email, $type)
});

I don't know if the quoting is managed by your modules but I've always found you need to quote anything but an integer:

INSERT INTO processo (process, name, email, type) VALUES ('$process','$lawyer', '$email', '$type')
});

"Lawyer: ",textfield('nome'),

Overlooked typo obviously. :-)

Hope some of this led you down the debugging path.