LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   storing complete email address in mysql using perl (https://www.linuxquestions.org/questions/linux-newbie-8/storing-complete-email-address-in-mysql-using-perl-4175430418/)

zak100 10-04-2012 01:14 AM

storing complete email address in mysql using perl
 
Hi,
I am trying to store complete email address in mysql db, but its not storing '@' symbol. Kindly guide me. I am working on Fedora 10.
My perl code is as follows:

Code:

#!/usr/bin/perl
use DBI;
$dbh=DBI->connect('dbi:mysql:perltest','root','')
or die "connection error : dbi:: errstr\n";
$username="ssuet2";
$email="ssuet2@edu.pk";


$sql="insert into subcribers(username, emailaddr) values ('$username','$email')";
$th=$dbh->prepare($sql);
$th->execute
or die "SQL Error: $DBI::errstr\n";

$username="ssuet3";
$email="ssuet3@edu.pk";


$sql="insert into subcribers(username, emailaddr) values ('$username','$email')";
$th=$dbh->prepare($sql);
$th->execute
or die "SQL Error: $DBI::errstr\n";

The ouput of mysql is:
Code:


mysql> select * from subcribers;
+-----+----------+-----------+
| uid | username | emailaddr |
+-----+----------+-----------+
|  1 | ssuet1  | ssuet1.pk |
|  2 | ssuet2  | ssuet2.pk |
|  3 | ssuet3  | ssuet3.pk |
+-----+----------+-----------+
3 rows in set (0.00 sec)

mysql>

Somebody plz guide me with this problem.

Zulfi.

chrism01 10-04-2012 05:10 AM

I'm a little surprised you didn't get an error there... anyway, first I recommend using best practice and amending the top of your prog thus
Code:

#!/usr/bin/perl -w
use DBI;
use strict;

then externally use
Code:

perl -wc myperl.pl
and fix any errors and warnings displayed.

Secondly, look at the paragraph here that mentions '$dbh->quote($string) method' http://www.perlmonks.org/?node_id=162771
See also http://search.cpan.org/~timb/DBI/DBI.pm


All times are GMT -5. The time now is 01:43 AM.