Form problems, post method yeilds 0 at end of values

D

David Mills

First of all hello to the group

I'm relativly new to perl, so if this is a stupid question, I'll accept my
due flaming.

I've written a small script to take user information and insert it into a
database, before creating an account for the user (this is obviously for
internal use only, and has the relevant .htaccess to prevent unorthorised
use).

The problem is that when the form is submitted, I get 0 at the end of each
value field (and by this I mean a hex 0 in the field, I've checked this
with a hex editor).

My question is how to remove these zeros, since they muck up the user
creation and the insertion into the database.

Google has shown up nothing relating to this

I've quoted part of the script below which shows these symptomes


Thanks in advance for your time

David Mills

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

print "Content-type: text/html\n\n";

#get info from form, lifted from http://www.cgi101.com, great site
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
print "$buffer\n";
print "\n";
@pairs = split(/\n/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
$FORM{$name} =~ s/\0//eg;
print "$name = $FORM{$name}t<br>";#Puts a 0 between the variable and the t
}
 
D

D Borland

I'm sure that the 0 is the end of string notififer (or something like that)
that c/c++ need/put at the end of the fields. I'm sure that you can just
chop it off when you don't want it, and put it back on when you do (isn't it
/0 anyhow?)

Dagmar
 
D

David Mills

I'm sure that the 0 is the end of string notififer (or something like that)
that c/c++ need/put at the end of the fields. I'm sure that you can just
chop it off when you don't want it, and put it back on when you do (isn't it
/0 anyhow?)

Dagmar
Already tried, useing regexp on the values doesn't work.
 
D

David Mills

David Mills wrote:

(snipped)



Others I am certain will fall for your troll article and
write stupid flame articles for a week.

This is not a flame, it's a request for help.
There is a problem. Your example is not from cgi101.com which
annoys me a bit. Deceit is one of my activation buttons.
That's where I got it from originally. Afterwoods I added a =~ or 2 too
try and resolve my problem, but the essientel of that part remained
unchainged. As for what was before and after, that's all my stuff.
Purl Gurl

Sorry Purl, I never meant any offense by posting this, I hate trolls as
much as the next poster, but in this case, I couldn't resolve this with
google's help alone, so I was obliged to post. It's just that as a maner
of course I keep referances to where I got code from, so that I can trace
code, and so that I know where to refer to if I mucked a certain bit up.

No offence meant, I assure you

David
 
D

D Borland

Dude,

This should help you ...

$theRecordFromTheDatabase =~ s/\0$//;

That should do it for you, but you need to add it back on when you want to
write back to database. I'm a bit of a novice, so look into it.

You are more than ok to post a question like yours, there was nothing wrong
with asking that. You've no-need to apologise.

If memory serves me correctly (which it usualy doesn't) Purl Gurl is a
troll - DON'T FEED IT!


Dagmar
 
D

David Mills

Dude,

This should help you ...

$theRecordFromTheDatabase =~ s/\0$//;

That should do it for you, but you need to add it back on when you want to
write back to database. I'm a bit of a novice, so look into it.

You are more than ok to post a question like yours, there was nothing wrong
with asking that. You've no-need to apologise.

If memory serves me correctly (which it usualy doesn't) Purl Gurl is a
troll - DON'T FEED IT!


Dagmar
Thanks, I'll try it tommorow as soon as I get into work, but it looks
good. BTW it was the zeros that were stopping me getting the thing into
the database, so I think you've just solved my last problem with this one,
Thanks again...

David
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

First of all hello to the group

Hi. Welcome.

#get info from form, lifted from http://www.cgi101.com, great site

It can't possibly be a great site if it gave you this shitty code.

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

What if the form is submitted via GET method?
print "$buffer\n";
print "\n";
@pairs = split(/\n/, $buffer);

CGI variables are not separated by newlines. They are separated by
ampersands or semicolons.
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

What if the value contains an equals sign?
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
$FORM{$name} =~ s/\0//eg;
print "$name = $FORM{$name}t<br>";#Puts a 0 between the variable and
the t }


Do this instead:

use CGI;
my $q = new CGI;
foreach my $p ($q->param)
{
print "[$p] => [", $q->param($p), "]<br />\n";
}

and see if those zeroes are still there. If so, they came in from the
form submission, and are not the fault of your program.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP29QcmPeouIeTNHoEQICeACg3aRlw3wpuBCj+qUgKZ0eT0GX9rkAoLEt
RfupQUyWFvruaRKK6hYt5R7f
=eHYM
-----END PGP SIGNATURE-----
 
D

David Mills

It is of interest, both of you display precisely
the same type of spelling errors and grammatical
errors. Quite the coincidence, that.

If your that paranoid, please check the servers, chances are we aren't
even in the same country, let alone on the same ISP
Incidently, neither of "you" mention a problem
with splitting on a newline for post data.
the splitting came from the 0's, or at least that's what it seemed like.
As I said in my last post to you, I didn't mean any offence, and I am not
trolling. Please accept my appologies for any offence caused by my first
post.

David Mills
 
D

David Mills

Do this instead:

use CGI;
my $q = new CGI;
foreach my $p ($q->param)
{
print "[$p] => [", $q->param($p), "]<br />\n";
}

and see if those zeroes are still there. If so, they came in from the
form submission, and are not the fault of your program.
Thanks, I'll try it, as for the example, it was much cleaner when I got
it, but as I started experimenting because of the problem I had, it got
messed up a bit.

Thanks again

David Mills
 
D

David Mills

Do this instead:

use CGI;
my $q = new CGI;
foreach my $p ($q->param)
{
print "[$p] => [", $q->param($p), "]<br />\n";
}

and see if those zeroes are still there. If so, they came in from the
form submission, and are not the fault of your program.
Thanks, I'll try it, as for the example, it was much cleaner when I got
it, but as I started experimenting because of the problem I had, it got
messed up a bit.
Right, they're still there, so I'll have to look else where for the
problem, thanks again to all who helped.

David Mills
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top