By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,051 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,051 IT Pros & Developers. It's quick & easy.

ISSET problem for a newby

P: n/a
Dear NG'ers,

I try to learn PHP and found several examples for a HTML form to add a
record to a database. I started out with just checking the workings of a
html form with PHP and am completely confused with the workings.

If I use GET to send the form I can clearly see the information exists. But
the second time the page is requested the action i expect (no show of the
form) is not executed.
The POST to send the form results in the same behavior.
I changed the location of the function to write the form from the body to
the head section and there is no difference in the behavior (as expected)

This is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>ISSET1 testen</title>
<?php
function schrijfForm() {
print "<form action=\"isset_test1.php\" method=\"POST\" >\n" ;
print "Voer nieuwe tekst in... \t" ;
print "<input type=\"text\" name=\"tekst1\">\n " ;
print "<input type=\"submit\" value=\"Voeg Toe!\"
name=\"ditform\">\n</form>\n" ;
}
?>
</head>
<body>
<?php
if ( isset( $ditform ) ) {
print "\$ditform is gezet: \t$ditform\n" ;
print "\$tekst1 is gezet: \t$tekst1\n" ;
} else {
print "HET BESTAAT NIET\n" ;
schrijfForm() ;
}
?>
<p>wat tekst </p>
</body>
</html>

I would appreciate some explanation of why this code doesn't work?

tia

pablo k

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
pablo wrote:

I would appreciate some explanation of why this code doesn't work?


This one works fine:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>ISSET1 testen</title>
<?php
function schrijfForm() {
print "<form action=\"test.php\" method=\"POST\" >\n" ;
print "Voer nieuwe tekst in... \t" ;
print "<input type=\"text\" name=\"tekst1\">\n " ;
print "<input type=\"submit\" value=\"Voeg Toe!\"
name=\"ditform\">\n</form>\n" ;
}
?>
</head>
<body>
<?php
$ditform = $_POST["ditform"];
$tekst1 = $_POST["tekst1"];
if ( isset( $ditform ) ) {
print "\$ditform is gezet: \t$ditform\n" ;
print "\$tekst1 is gezet: \t$tekst1\n" ;
} else {
print "HET BESTAAT NIET\n" ;
schrijfForm() ;
?>
<p>wat tekst</p>
</body>
</html>
The reason seems to be that register_globals is off, as it should due to
some security.
Now, your form is posting the data, but due to register_globals being off,
nothing is receiving the data.
That's why $_POST is used to get the data, for consistency the posted
variables are assigned to the original variables.

Pay attention to the fact, that I renamed the form to run for test.php, so
the above code _must_ be in a page named test.php - or if you stick to the
original form, the page where the code appears _must_ then be named
isset_test1.php else it will fail - it is self referencing (calling
itself).
Self reference can also be obtained using $PHP_SELF.

HTH,

Andreas
--
Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #2

P: n/a

"Andreas Paasch" <An*****@Paasch.Net> wrote in message
news:av**********************@news000.worldonline. dk...
(...some deleted code)
The reason seems to be that register_globals is off, as it should due to
some security.
Now, your form is posting the data, but due to register_globals being off,
nothing is receiving the data.
That's why $_POST is used to get the data, for consistency the posted
variables are assigned to the original variables.

Pay attention to the fact, that I renamed the form to run for test.php, so
the above code _must_ be in a page named test.php - or if you stick to the
original form, the page where the code appears _must_ then be named
isset_test1.php else it will fail - it is self referencing (calling
itself).
Self reference can also be obtained using $PHP_SELF.

HTH, So happy to be on the receiving end of your HELP!
I have been wondering and experimenting for three whole days!

Friede und ein langes Leben, indeed.

Andreas
--
Peace and long life ...
Registeret Linux user #292411

Jul 17 '05 #3

P: n/a
Andreas Paasch wrote:
pablo wrote:

I would appreciate some explanation of why this code doesn't work?


This one works fine:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>ISSET1 testen</title>
<?php
function schrijfForm() {
print "<form action=\"test.php\" method=\"POST\" >\n" ;
print "Voer nieuwe tekst in... \t" ;
print "<input type=\"text\" name=\"tekst1\">\n " ;
print "<input type=\"submit\" value=\"Voeg Toe!\"
name=\"ditform\">\n</form>\n" ;
}

</head>
<body>
<?php
$ditform = $_POST["ditform"];
$tekst1 = $_POST["tekst1"];
if ( isset( $ditform ) ) {
print "\$ditform is gezet: \t$ditform\n" ;
print "\$tekst1 is gezet: \t$tekst1\n" ;
} else {
print "HET BESTAAT NIET\n" ;
schrijfForm() ;

<p>wat tekst</p>
</body>
</html>
The reason seems to be that register_globals is off, as it should due
to some security.
Now, your form is posting the data, but due to register_globals being
off, nothing is receiving the data.
That's why $_POST is used to get the data, for consistency the posted
variables are assigned to the original variables.

Pay attention to the fact, that I renamed the form to run for
test.php, so the above code _must_ be in a page named test.php - or
if you stick to the original form, the page where the code appears
_must_ then be named isset_test1.php else it will fail - it is self
referencing (calling itself).
Self reference can also be obtained using $PHP_SELF.

HTH,

Andreas


Actually, $PHP_SELF requires register_globals = On;
Instead, use $_SERVER['PHP_SELF']
Jul 17 '05 #4

P: n/a
Agelmar wrote:
Andreas Paasch wrote:
pablo wrote:

I would appreciate some explanation of why this code doesn't work?


This one works fine:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>ISSET1 testen</title>
<?php
function schrijfForm() {
print "<form action=\"test.php\" method=\"POST\" >\n" ;
print "Voer nieuwe tekst in... \t" ;
print "<input type=\"text\" name=\"tekst1\">\n " ;
print "<input type=\"submit\" value=\"Voeg Toe!\"
name=\"ditform\">\n</form>\n" ;
}

</head>
<body>
<?php
$ditform = $_POST["ditform"];
$tekst1 = $_POST["tekst1"];
if ( isset( $ditform ) ) {
print "\$ditform is gezet: \t$ditform\n" ;
print "\$tekst1 is gezet: \t$tekst1\n" ;
} else {
print "HET BESTAAT NIET\n" ;
schrijfForm() ;

<p>wat tekst</p>
</body>
</html>
The reason seems to be that register_globals is off, as it should due
to some security.
Now, your form is posting the data, but due to register_globals being
off, nothing is receiving the data.
That's why $_POST is used to get the data, for consistency the posted
variables are assigned to the original variables.

Pay attention to the fact, that I renamed the form to run for
test.php, so the above code _must_ be in a page named test.php - or
if you stick to the original form, the page where the code appears
_must_ then be named isset_test1.php else it will fail - it is self
referencing (calling itself).
Self reference can also be obtained using $PHP_SELF.

HTH,

Andreas


Actually, $PHP_SELF requires register_globals = On;
Instead, use $_SERVER['PHP_SELF']


You are correct, I just pulled it out of memory ... haven't been on PHP for
a while, fighting with setting up a mailserver to my needs ...

--
Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #5

P: n/a
Thanks a lot to all respondents!

pablo k
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.