Re: questions about bind_param and mysql trace data included

2004-05-11 Thread Brad Lhotsky
Try this:

On Tue, May 11, 2004 at 12:51:28PM -0700, [EMAIL PROTECTED] wrote:
 
 
 below I have a snippet from a trace file read out for a section of code below. The 
 problem seems to be with '$sth-bind_param (2,$rh_row-{prop_str_addr});' The first 
 Bind works fine however the next one in the line listed produces a null entry per 
 the trace file. I have verified that the data is correct in 
 '$rh_row-{prop_str_addr}' and that it is quoted but for some reason myql isn't 
 recieving the data any help would be appreciated.
 
 - dbd_st_execute 0 rows
 - execute= '0E0' at db_load_1-2.pl line 128
 - bind_param for DBD::mysql::st (DBI::st=HASH(0x8104f14)~0x8104e3c 1 
 ''310-673-5515'')
 - bind_param= 1 at db_load_1-2.pl line 122
 - execute for DBD::mysql::st (DBI::st=HASH(0x8104f14)~0x8104e3c)
 - dbd_st_execute for 08104e48
   Binding parameters: UPDATE own_info
SET own_phone_home = '\'310-673-5515\''
WHERE own_str_addr = NULL
 
 
 
 ###CODE SNIPPETTE
 $dbh = connect_try(**,**);
 foreach $k (keys (%{$ar_info-[1]})){ # retrieves a generic set of fields and 
 uses them to assign values for each row.
 if ($table eq prop_info){ # checks which table is being used and assigns 
 the correct SQL statement
 $sth = $dbh-prepare (UPDATE prop_info
SET $k = ?
WHERE prop_str_addr = ?) or
err_trap(failed to prepare statement\n);
 }elsif ($table eq own_info){
 $sth = $dbh-prepare (UPDATE own_info
SET $k = ?
WHERE own_str_addr = ?) or
err_trap(failed to prepare statement\n);
 
 
 }
 $sth-trace(2, ./trace_data.txt);
 foreach $rh_row (@$ar_info) { # iterates through the list of rows and 
 assigns the correct value to the field
 print ::$k=$rh_row-{$k}; # this is an internal check to verify what 
 values are being inserted
 $sth-bind_param (1,$rh_row-{$k});

  if($table eq 'prop_info') {

 if ($table eq prop_str_addr) {
 $sth-bind_param (2,$rh_row-{prop_str_addr});
 }elsif  ($table eq own_str_addr) {
 $sth-bind_param (2,$rh_row-{own_str_addr});
 }
 $sth-execute() or
 err_trap(failed to execute statement\n);
 
 }
 print \n===\n;
 
 }
 $sth-finish();
 $dbh-disconnect or
 err_trap(failed to disconnect statement\n);
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 

-- 
Brad Lhotsky [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to set env variables?

2004-05-11 Thread Reynard Hilman
I think I figured it out now, I set it from the httpd.conf like this
SetEnv VAR Value
and restart the apache, now it works.
thank you all for the suggestions,
- reynard
Charles K. Clarkson wrote:

Reynard Hilman [EMAIL PROTECTED] wrote:
:
: I have a perl script that runs just fine from command
: line but not when I run it as cgi. I think it's because
: there are some env variables that doesn't exist when I
: run it as cgi. Is there a way to set the variables from
: the perl script?
: I tried $ENV{'VAR'} = 'value';
   That usually works.

: but it doesn't make a difference.

   Perhaps it's not an environment variable problem.

: btw, I'm using Apache as the webserver. Should I set
: the env variables from Apache config instead?
   That will set the variable across the entire server
and is one recommended way. What happened when you tried
that?
: any suggestion?

   Show us your code. Let us confirm your reasoning.

HTH,

Charles K. Clarkson
 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Escaping quotes in variable content

2004-05-11 Thread Jan Eden
Hi all,

how can I escape quotes within a variable's content? I use the following directive to 
fill an HTML form:

input type=text name=frage_text size=100 value=$frage_text /

Unfortunately, if $frage_text contains a double quote, the browser will stop 
displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =~ s//\\/g;

but that did not help.
 
 Any suggestion is appreciated.
 
 Thanks,
 
 Jan
-- 
Common sense is what tells you that the world is flat.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping quotes in variable content

2004-05-11 Thread David Dorward
On 11 May 2004, at 14:58, Jan Eden wrote:
how can I escape quotes within a variable's content? I use the 
following directive to fill an HTML form:
input type=text name=frage_text size=100 value=$frage_text /
Unfortunately, if $frage_text contains a double quote, the browser 
will stop displaying the string at that point.
I tried to escape the quotes in a Perl way
$frage_text =~ s//\\/g;
In HTML characters are 'escaped' by converting them to entities. 
entityName; Quote marks are quot;

You probably want to use escapeHTML() from the CGI module.

--
David Dorward
 http://dorward.me.uk/
http://blog.dorward.me.uk/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Escaping quotes in variable content

2004-05-11 Thread Jan Eden
Hi David,

David Dorward wrote on 11.05.2004:

On 11 May 2004, at 14:58, Jan Eden wrote:
how can I escape quotes within a variable's content? I use the
following directive to fill an HTML form: input type=text
name=frage_text size=100 value=$frage_text / Unfortunately,
if $frage_text contains a double quote, the browser will stop
displaying the string at that point. I tried to escape the quotes
in a Perl way $frage_text =~ s//\\/g;

In HTML characters are 'escaped' by converting them to entities.
entityName; Quote marks are quot;

You probably want to use escapeHTML() from the CGI module.

Doh. I have been working on the script for several hours now and forgot the most 
simple things about HTML.

Thanks,

Jan
-- 
Common sense is what tells you that the world is flat.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Displaying Data in a Table

2004-05-11 Thread John Mooney
Late to the question, but don't discount using a simple pre/pre (pre-formatted) 
tag either ... keeps things lined up nicely in a mono-spaced font. I often use this 
for short web-ified shell cmd results.
 
 #!/usr/local/bin/perl -w
 
  print Content-type: text/html\n\n;
  our @cmd = `df -sk|fgrep -v nfs|sort +3 -r`;  ## filter out cross-mounted w/fgrep -v
  print EOF;
  html
  head
   titleDiskFree on Weabpp/title
  /head
  body
h2webapp disk free results/h2
(results of df -sk | fgrep -v nfs| sort +3 -r)
p
 hr
pre
 @cmd
/pre
hr
/body
/html
 
 EOF

FYI
 
 

 Charles K. Clarkson [EMAIL PROTECTED] 5/8/2004 10:11:34 AM  
Baek, Steve  [EMAIL PROTECTED]  wrote: 
: 
: I'm trying to break apart the command `df -k` data 
: and display it into an html table: 
: 
: Filesystem kbytes used avail capacity Mounted on 
: /dev/dsk/c0t2d0s0 3008783 83669 2864939 3% / 
: /dev/dsk/c0t2d0s3 4032654 886633 3105695 23% /usr 
: /proc 0 0 0 0% /proc 
: mnttab 0 0 0 0% /etc/mnttab 
: fd 0 0 0 0% /dev/fd 
: /dev/dsk/c0t2d0s7 19808378 250080 19360215 2% /var 
: swap 594216 104 594112 1% /var/run 
: swap 594448 336 594112 1% /tmp 
: /dev/dsk/c0t2d0s6 1985487 532663 1393260 28% /export 
: /dev/dsk/c0t2d0s5 1985487 356649 1569274 19% /opt 
: /dev/dsk/c0t2d0s4 7057565 914628 6072362 14% /usr/local 


: Would anyone happen to know the best way to do this? 

Not the best way, No. 


: I'm thinking of putting each line into an array... 

Sounds like a plan ... 

The most obvious method to break this apart is using 'split'. 
Since Mounted on contains a space we need to limit the split to 
6 columns: 

#!/usr/bin/perl 

use strict; 
use warnings; 
use Data::Dumper 'Dumper'; 

while ( DATA ) { 
chomp; 
print Dumper [ split ' ', $_, 6 ]; 
} 

__END__ 
Filesystem kbytes used avail capacity Mounted on 
/dev/dsk/c0t2d0s0 3008783 83669 2864939 3% / 
/dev/dsk/c0t2d0s3 4032654 886633 3105695 23% /usr 
/proc 0 0 0 0% /proc 
mnttab 0 0 0 0% /etc/mnttab 
fd 0 0 0 0% /dev/fd 
/dev/dsk/c0t2d0s7 19808378 250080 19360215 2% /var 
swap 594216 104 594112 1% /var/run 
swap 594448 336 594112 1% /tmp 
/dev/dsk/c0t2d0s6 1985487 532663 1393260 28% /export 
/dev/dsk/c0t2d0s5 1985487 356649 1569274 19% /opt 
/dev/dsk/c0t2d0s4 7057565 914628 6072362 14% /usr/local 



CGI.pm provides a td() function for cell data. It accepts 
a reference to an array for multiple cells. 

use CGI qw( table Tr td ); 

my @rows; 
while ( DATA ) { 
chomp; 
push @rows, 
Tr( 
td( [ split ' ', $_, 6 ] ) 
); 
} 
print table( @rows ); 


Or as a subroutine: 

use CGI qw( table Tr td ); 

print table_ize( *DATA ); 

sub table_ize { 
my $file_handle = shift; 

my @rows; 
while ( $file_handle ) { 
chomp; 
push @rows, 
Tr( 
td( [ split ' ', $_, 6 ] ) 
); 
} 
return table( @rows ); 
} 


: Does anyone have any thoughts? 

Not on a Saturday, no. 

HTH, 

Charles K. Clarkson 
-- 
Mobile Homes Specialist 
254 968-8328 




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Ash Singh


Try this:
input type=\text\ name=\frage_text\ size=\100\ value=\$frage_text\



-Original Message-
From: Jan Eden [mailto:[EMAIL PROTECTED] 
Sent: 11 May 2004 03:59 PM
To: Perl Lists
Subject: Escaping quotes in variable content

Hi all,

how can I escape quotes within a variable's content? I use the following
directive to fill an HTML form:

input type=text name=frage_text size=100 value=$frage_text /


Unfortunately, if $frage_text contains a double quote, the browser will stop
displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =~ s//\\/g;

but that did not help.
 
 Any suggestion is appreciated.
 
 Thanks,
 
 Jan
-- 
Common sense is what tells you that the world is flat.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Ash Singh
This is better, replace the quotes with nothing and then build your input
tag.

#!/usr/bin/perl

use CGI;
use strict;

my $cgi = new CGI; print $cgi-header;
my $query = CGI::new();

my $frage_text= \Hello World\;

$frage_text =~ s///g;

print form name=\test\ action=\http://www.somewhere.com\;\n;
printinput type=\text\ name=\frage_text\ size=\100\
value=\$frage_text\ /\n;
print /form\n;

I hope this helps 
Regards Ash.



-Original Message-
From: Jan Eden [mailto:[EMAIL PROTECTED] 
Sent: 11 May 2004 04:21 PM
To: David Dorward; Perl Lists
Subject: Re: Escaping quotes in variable content

Hi David,

David Dorward wrote on 11.05.2004:

On 11 May 2004, at 14:58, Jan Eden wrote:
how can I escape quotes within a variable's content? I use the
following directive to fill an HTML form: input type=text
name=frage_text size=100 value=$frage_text / Unfortunately,
if $frage_text contains a double quote, the browser will stop
displaying the string at that point. I tried to escape the quotes
in a Perl way $frage_text =~ s//\\/g;

In HTML characters are 'escaped' by converting them to entities.
entityName; Quote marks are quot;

You probably want to use escapeHTML() from the CGI module.

Doh. I have been working on the script for several hours now and forgot the
most simple things about HTML.

Thanks,

Jan
-- 
Common sense is what tells you that the world is flat.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Wiggins d Anconia
Please bottom post...

 This is better, replace the quotes with nothing and then build your input
 tag.
 

Better?  You have destroyed the data.  Stay away from my information
with your substituitions.

[snip code that should not be used in production]

 
 I hope this helps 

Anyone reading the archive, please don't do this.  escapeHTML or
HTML::Entities should do very well.

http://danconia.org

 
 
 -Original Message-
 From: Jan Eden [mailto:[EMAIL PROTECTED] 
 Sent: 11 May 2004 04:21 PM
 To: David Dorward; Perl Lists
 Subject: Re: Escaping quotes in variable content
 
 Hi David,
 
 David Dorward wrote on 11.05.2004:
 
 On 11 May 2004, at 14:58, Jan Eden wrote:
 how can I escape quotes within a variable's content? I use the
 following directive to fill an HTML form: input type=text
 name=frage_text size=100 value=$frage_text / Unfortunately,
 if $frage_text contains a double quote, the browser will stop
 displaying the string at that point. I tried to escape the quotes
 in a Perl way $frage_text =~ s//\\/g;
 
 In HTML characters are 'escaped' by converting them to entities.
 entityName; Quote marks are quot;
 
 You probably want to use escapeHTML() from the CGI module.
 
 Doh. I have been working on the script for several hours now and
forgot the
 most simple things about HTML.
 
 Thanks,
 
 Jan



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Jan Eden
[EMAIL PROTECTED] wrote on 11.05.2004:

 print form name=\test\ action=\http://www.somewhere.com\;\n;
 printinput type=\text\ name=\frage_text\ size=\100\
 value=\$frage_text\ /\n;
 print /form\n;

This wasn't really the question, but... 
If you have to write html within perl, use qq( ) instead of .
It's a lot easier to read, and much less error prone.

ie,
print qq(
form name=test action=http://www.somewhere.com;
input type=text name=frage_text size=100 value=$frage_text /
/form
);


I did use qq{} quoting within the Perl script in the first place. My problem was 
related to quoting within a double-quoted HTML attribute, e.g.

input value=This quot;personquot; /

Thanks,

Jan
-- 
Either this man is dead or my watch has stopped. - Groucho Marx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




questions about bind_param and mysql trace data included

2004-05-11 Thread smrtalec


below I have a snippet from a trace file read out for a section of code below. The 
problem seems to be with '$sth-bind_param (2,$rh_row-{prop_str_addr});' The first 
Bind works fine however the next one in the line listed produces a null entry per the 
trace file. I have verified that the data is correct in '$rh_row-{prop_str_addr}' and 
that it is quoted but for some reason myql isn't recieving the data any help would be 
appreciated.

- dbd_st_execute 0 rows
- execute= '0E0' at db_load_1-2.pl line 128
- bind_param for DBD::mysql::st (DBI::st=HASH(0x8104f14)~0x8104e3c 1 
''310-673-5515'')
- bind_param= 1 at db_load_1-2.pl line 122
- execute for DBD::mysql::st (DBI::st=HASH(0x8104f14)~0x8104e3c)
- dbd_st_execute for 08104e48
  Binding parameters: UPDATE own_info
   SET own_phone_home = '\'310-673-5515\''
   WHERE own_str_addr = NULL



###CODE SNIPPETTE
$dbh = connect_try(**,**);
foreach $k (keys (%{$ar_info-[1]})){ # retrieves a generic set of fields and uses 
them to assign values for each row.
if ($table eq prop_info){ # checks which table is being used and assigns the 
correct SQL statement
$sth = $dbh-prepare (UPDATE prop_info
   SET $k = ?
   WHERE prop_str_addr = ?) or
   err_trap(failed to prepare statement\n);
}elsif ($table eq own_info){
$sth = $dbh-prepare (UPDATE own_info
   SET $k = ?
   WHERE own_str_addr = ?) or
   err_trap(failed to prepare statement\n);


}
$sth-trace(2, ./trace_data.txt);
foreach $rh_row (@$ar_info) { # iterates through the list of rows and assigns 
the correct value to the field
print ::$k=$rh_row-{$k}; # this is an internal check to verify what 
values are being inserted
$sth-bind_param (1,$rh_row-{$k});
if ($table eq prop_str_addr) {
$sth-bind_param (2,$rh_row-{prop_str_addr});
}elsif  ($table eq own_str_addr) {
$sth-bind_param (2,$rh_row-{own_str_addr});
}
$sth-execute() or
err_trap(failed to execute statement\n);

}
print \n===\n;

}
$sth-finish();
$dbh-disconnect or
err_trap(failed to disconnect statement\n);


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response