Net-MySQL - Need help on inserting values into table

Posted on Wed Sep 24 13:38:51 2008 by karthikkashyap
Need help on inserting values into table
Hi guys, I am new to using Net::MySQL module. I want to know how to insert values in a variable into the table. Following is the piece of code I have written. I am able to insert scalar values into the table but not able to write the values present in a variable into the table. Can you please help?
#!/usr/bin/perl use CGI; use Net::MySQL; my $mysql = Net::MySQL->new( hostname => '10.111.0.94', database => 'test', user => 'karthik', password => 'kashyap' ); print "Content-type: text/html\n\n"; $cgi=new CGI; $Uexist = 1; $username = $cgi->param('USERNAME'); chomp $username; if (!$Uexist) { $password = $cgi->param('PASSWD'); chomp $password; $passretype = $cgi->param('REPASSWD'); chomp $passretype; $email = $cgi->param('EMAIL'); chomp $email; $role = $cgi->param('Roles'); chomp $role; if ($password eq $passretype) { $mysql->query(q{ INSERT INTO userdata (username,password,mail,role) VALUES ($username,$password,$email,$role) }); print "Affected row: $mysql->get_affected_rows_length"; last; } else { print "<html><head><title>Warning</title></head><body>"; print "<font color=red><h2>Password does not match.</h2>"; print "</table></center></body></html>"; } } $mysql->close;
- Thanks and Regards, Karthik
Write a response