Forum Moderators: coopster & phranque

Message Too Old, No Replies

Data Input into CGI Scripts

Basic Data Input into CGI Scripts

         

bbm_builder

1:02 am on Jan 24, 2006 (gmt 0)

10+ Year Member



I am trying to input data from an HTML Form into a CGI Script. I am followng the instructions from a book I am reading, CGI Programming 101, where the author suggest a line of text: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

It then goes on to put the values into a hash called %FORM: $FORM{$name} = $value;

However, when I attempt to access the keys of %FORM, for example, $FORM{'name'} or $FORM{'email'}....my CGI Script erases the keys from the script, in these cases, $FORM{'name'} or $FORM{'email'} then it gives me an error message. Does anyone know why this is happening and is there a better way to transfer data from a HTML Form into a CGI Script that you can share with me.

Thanks,

simon2263

7:34 am on Jan 24, 2006 (gmt 0)

10+ Year Member



It's hard to tell what the problem is without seeing the actual code. Is the HTML form using the POST method? Under the CGI protocol, data sent using POST is put onto the CGI program's STDIN input stream, but if the form uses GET, then the form data is in the QUERY_STRING environment variable.

Do the values you use to index into the FORM has exactly match the names of the input fields on the HTML form? You could do some debugging by printing out the entire hash - for example:

while ( ($k,$v) = each %FORM ) {
print "$k => $v\n";
}

This would tell you what was actually stored in it. Ideally, the keys ($k above) should be the HTML input field names, and the values ($v above) should be the user-entered data for each input field.

Simon

perl_diver

9:58 am on Jan 24, 2006 (gmt 0)

10+ Year Member



post your code, it's a waste of time trying to speculate on your question. There is certainly no reason why simply accessing a hash key should delete the key from the hash.

Xenon001

8:13 am on Jan 25, 2006 (gmt 0)

10+ Year Member



uh and "deleting" a key from a hash has to be done very explicit.

if ( $myHash{test} ) { # key test has just been created!
$myHash{test} = ""; # key "test" still exisit
}

undef($myHash{test}); # key "test" still exists

if ( exists $myHash{test} ) {
print "omg its true the key is still there ...";
}

delete($myHash{test}); # finaly its gone ...

if ( exists $myHash{test} ) {
print "#*$!?! ...";
} else {
print "finaly ... its gone";
}

I belive you do not get the value at all. ( typo in hash key etc ... ) You are creating the "key" with a test or something like that (eg: print $myHash{'test'} )some where on the fly.

watch fot typos like these:

<input type="text" name="Email">
.
.
.
.

email_send_function( $myHash{'email'}, $myHash{'text'});

$myHash{'email'} exsists now! but with "undef" as value.

bbm_builder

3:33 am on Jan 31, 2006 (gmt 0)

10+ Year Member



Thanks to all who replied, I appreciate the help.