in reply to Re: Recalcitrant placeholders
in thread Recalcitrant placeholders
Instead of presenting us with bits of isolated code, please provide an SSCCE that reproduces your problem and is written in such a way that we can run it and help you towards a solution.
I cannot reproduce the problem myself...
To try and get to the bottom of the problem, I have written this script:
This correctly dumps the table data and then displays CRID: 2#!/usr/bin/perl -T use CGI::Carp qw(fatalsToBrowser); use FindBin qw($RealBin); my $safepath; BEGIN { if ($RealBin =~ m!^(/home/username/uk/www)!) { $safepath = "$1/../lib"; } else { die "Illegal use of software - visit www.example.com to use th +is site"; } } use lib "$safepath"; use Site::HTML; use Site::Wayfinder; use Bod::CRM; use strict; use warnings; my $crm = Bod::CRM->new('test'); print "Content-type: text/plain\n\n"; my $db = '...'; my $un = '...'; my $pw = '...'; ##### Uncomment one line ##### #my $dbh = DBI->connect("dbi:mysql:$db:localhost:3306",$un,$pw) || die + "DB ERROR: " . $dbh->errstr; my $dbh = $crm->db; $dbh->do("CREATE TEMPORARY TABLE Temp_Test ( idTest INT NOT NULL AUTO_INCREMENT PRIMARY KEY, fname VARCHAR(40), nname VARCHAR(40), sname VARCHAR(60), email VARCHAR(100), altEmail VARCHAR(100) ) ENGINE MyISAM"); print "ERROR: " . $dbh->errstr if $dbh->err; $dbh->do("INSERT INTO Temp_Test (fname, nname, sname, email) VALUES (' +Ian', 'Bod', 'Boddison', 'me\@example.com')"); $dbh->do("INSERT INTO Temp_Test (fname, nname, sname, email) VALUES (' +Boomer', 'Boo', 'Dog', 'dog\@example.com')"); $dbh->do("INSERT INTO Temp_Test (fname, nname, sname, email) VALUES (' +Oi', '', 'You', 'you\@example.com')"); my $query = $dbh->prepare("SELECT * FROM Temp_Test"); $query->execute; $, = ' - '; while (my @row = $query->fetchrow_array) { print @row; print "\n"; } my %data; $data{'email'} = 'dog@example.com'; my $crid = $dbh->selectrow_array("SELECT idTest FROM Temp_Test WHERE e +mail = ? OR altEmail = ?", undef, $data{'email'}, $data{'email'}); print "ERROR: " . $dbh->errstr if $dbh->err; print "\nCRID: $crid\n";
So what I have done is to go back to the code that is behaving strangely and double check it.
It has been stripped back to bare minimum and the strange result still happens:
This has two ways of getting the same data from the database.#!/usr/bin/perl -T use CGI::Carp qw(fatalsToBrowser); use FindBin qw($RealBin); my $safepath; BEGIN { if ($RealBin =~ m!^(/home/username/uk/www)!) { $safepath = "$1/../lib"; } else { die "Illegal use of software - visit www.example.com to use th +is site"; } } use lib "$safepath"; use Site::HTML; use Site::Wayfinder; use Bod::CRM; use strict; use warnings; my $html = Site::HTML->new; my $wf = Site::Wayfinder->new; my $crm = Bod::CRM->new('test'); $html->head; my $logbox = 'log_login'; $logbox = 'log_fpass' if $data{'command'} eq 'fpass'; # Reset password if ($data{'command'} eq 'rpass') { my $test = $crm->db->selectrow_array("SELECT idPerson FROM Person +WHERE email = ? OR altEmail = ?", undef, $data{'email'}, $data{'email +'}); print "<p>TEST: $test</p>\n"; my $query = $crm->db->prepare("SELECT idPerson FROM Person WHERE e +mail = ? OR altEmail = ?"); $query->execute($data{'email'}, $data{'email'}); my $crid = $query->fetchrow_array; print "<p>CRID: $crid</p>\n"; exit; } __END__
The output is:
The selectrow_array function should not be able to return zero when zero does not exist anywhere in the idPerson field of the database.TEST: 0 CRID: 1
update:
Just to prove it is not something that is happening in Site::HTML->head, I have changed:
for$html->head;
and the output now is:#$html->head; print "Content-type: text/plain\n\n";
<p>TEST: 0</p> <p>CRID: 1</p>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Recalcitrant placeholders
by kcott (Archbishop) on Jul 07, 2021 at 07:04 UTC | |
by Bod (Parson) on Jul 09, 2021 at 18:03 UTC | |
by haukex (Archbishop) on Jul 09, 2021 at 19:51 UTC | |
by Bod (Parson) on Jul 10, 2021 at 13:45 UTC | |
by haukex (Archbishop) on Jul 17, 2021 at 19:40 UTC | |
| |
by hippo (Archbishop) on Jul 09, 2021 at 19:54 UTC |