Problem with DBI retrieving data entered

Problem with DBI retrieving data entered

am 10.08.2006 22:13:50 von Russbucket

Fairly new o using Perl and DBI.
Have mysql database on SUSE 10.0, perl-5.8.7-5.3, mysql-4.1.13-3.6. I am ab=
le=20
to insert the data from an html form but I want to print the last data=20
entered for verification. I keep getting the following errors (code shown=
=20
below):

/usr/bin/perl insertmember.cgi -cw
Content-type: text/html

DBD::mysql::st fetchrow_array failed: fetch() without execute() at=20
insertmember.cgi line 53.
DBD::mysql::st execute failed: You have an error in your SQL syntax; check =
the=20
manual that corresponds to your MySQL server version for the right syntax t=
o=20
use near '' at line 1 at insertmember.cgi line 56.
Member Information

Thank You


Thank you for adding information about a member. Your information was enter=
ed=20
into the database.




Code:
#Insert data
$sth =3D $dbh->prepare ("INSERT INTO Moses_Lake_Lions (First_Name, Last_Nam=
e,=20
Spouse, email, Home_Phone, Business_Phone, Cell_phone, Occupation_Employer,=
=20
Status_Key) Values=20
('$First_Name', '$Last_Name', '$Spouse', '$email', '$Home_Phone', '$Busines=
s_Phone', '$Cell_phone', '$Occupation_Employer', '$Status_Key')");

$rv =3D $sth->execute ();

#Retrieve data enter for verification
$sth =3D $dbh->prepare (qq {SELECT First_Name, Last_Name, Spouse, email,=20
Home_Phone, Business_Phone, Cell_phone, Occupation_Employer, Status_Key FRO=
M=20
Moses_Lake_Lions WHERE Last_Name =3D $Last_Name}) or dienice ("Cannot prepa=
re=20
statement:", $dbh->errstr);

#$rv =3D $sth->execute ();

while (($First_Name, $Last_Name, $Spouse, $email, $Home_Phone,=20
$Business_Phone, $Cell_phone, $Occupation_Employer, $Status_Key) =
$sth->fetchrow_array) {
=A0 =A0print "$First_Name - $Last_Name - $Spouse =A0- $email - $Home_Phone =
-=20
$Business_Phone - $Cell_phone - $Occupation_Employer - $Status_Key) \n";
=A0 =A0}
$rv =3D $sth->execute ();
#$rc =3D $sth ->finish;

#Disconnect from database
$dbh->disconnect ();
--=20
Russ

Re: Problem with DBI retrieving data entered

am 11.08.2006 01:50:12 von victorchurchill

On 10/08/06, Russbucket wrote:
> DBD::mysql::st execute failed: You have an error in your SQL syntax; check the
> manual that corresponds to your MySQL server version for the right syntax to
> use near '' at line 1 at insertmember.cgi line 56.

> Code:
> #Insert data
> $sth = $dbh->prepare ("INSERT INTO Moses_Lake_Lions (First_Name, Last_Name,
> Spouse, email, Home_Phone, Business_Phone, Cell_phone, Occupation_Employer,
> Status_Key) Values
> ('$First_Name', '$Last_Name', '$Spouse', '$email', '$Home_Phone', '$Business_Phone', '$Cell_phone', '$Occupation_Employer', '$Status_Key')");
>
> $rv = $sth->execute ();
>
> #Retrieve data enter for verification
> $sth = $dbh->prepare (qq {SELECT First_Name, Last_Name, Spouse, email,
> Home_Phone, Business_Phone, Cell_phone, Occupation_Employer, Status_Key FROM
> Moses_Lake_Lions WHERE Last_Name = $Last_Name}) or dienice ("Cannot prepare
> statement:", $dbh->errstr);

You need to quote the $Last_Name}) in the where clause.
Better to use $dbh->quote rather than do it directly. That also
applies to the Select.

hth

--
cheers,
victor

Victor Churchill, Bournemouth, U.K.

Re: Problem with DBI retrieving data entered

am 11.08.2006 17:58:43 von Russbucket

On Thursday 10 August 2006 16:50, you wrote:

> > #Retrieve data enter for verification
> > $sth = $dbh->prepare (qq {SELECT First_Name, Last_Name, Spouse, email,
> > Home_Phone, Business_Phone, Cell_phone, Occupation_Employer, Status_Key
> > FROM Moses_Lake_Lions WHERE Last_Name = $Last_Name}) or dienice ("Cannot
> > prepare statement:", $dbh->errstr);
>
> You need to quote the $Last_Name}) in the where clause.
> Better to use $dbh->quote rather than do it directly. That also
> applies to the Select.
>
> hth
Thanks Victor, I'll try that later today.
--
Russ