Jump to content

Recommended Posts

Hi,

I know I should find some more up to date material - but getting this problems is one way of REALLY understanding the code!

I have been following PHP 4 weekend crash course, and I cannot for the life of me get this to work.

If I create a form and $_POST to say handler.php
handler.php contains
<?php phpinfo() ?> // this works - if I scroll down to the variables I can see all the input from the form

however, if I change the form to $_POST to handler1.php, which contains
<?php
//Generic form data parser
// Begin HTML page and field table
echo "<html><head><title>Check Form</title></head><body><table cellpadding=20 border=1>";
echo "<tr><td><b>Name</b></td><td><b>Value</b></td></tr>";
// For each $_POST value
foreach ($_POST as $key => $value)
{ // Print the key in the first column
print "<tr><td>" . $key . "&nbsp; </td>\n";
print "<td>";

// If the field is an empty array, parse it
if (is_array($value))
{ foreach ($value as $selkey => $selvalue)
{ print $selkey . " : ". $selvalue ."&nbsp; <br />";}
} else { // Else (not array) just print the value
// in second column
print $value . "&nbsp;";
}
print "</td></tr>\n";
}
print "</table></body></html>";
?>

All I get is the HTML header

Can anyone help please ?
[code]
<?php
//Generic form data parser
// Begin HTML page and field table
echo "<html><head><title>Check Form</title></head><body><table cellpadding=20 border=1>";
echo "<tr><td><b>Name</b></td><td><b>Value</b></td></tr>";
// For each $_POST value
foreach ($_POST as $key => $value)
{ // Print the key in the first column
    print "<tr><td>" . $key . "&nbsp; </td>\n";
    print "<td>";
    
    // If the field is an empty array, parse it
    if (is_array($value))
    {
        foreach ($value as $selkey => $selvalue)
        {
            print $selkey . " : ". $selvalue ."&nbsp; <br />";
        }
    }
    else
    {
        // Else (not array) just print the value
        // in second column
        print $value . "&nbsp;";
    }
print "</td></tr>\n";
}
print "</table></body></html>";
?>
[/code]

worked absolutely fine for me.

try placing

[code]


<form method='post'>

<input type='text' name='test1' /><br />
<Input type='text' name='test2' /><br />
<input type='text' name='test3' /><br />
<input type='submit'>

</form>
[/code]

directly under the handler in handler1.php

load the page up and fill out the form. If you get it OK from there something's going wrong between your form and the handler page. Have you definitely set the action to the correct handler?
I thought with PHP 5 you were supposed to use the superglobal variables ?
I found with other forms I have had to use $_POST in all cases (POST returns blanks)
i.e. POST becomes $_POST

I tried it without the $_ and I still get the same

and if I use the same method ($_POST) with the phpinfo () I see the variables, so I assume that the form input is correct but somehow the variables are not being passed/parsed correctly in the handler1.php script but I cannot see why!

I dont think it is the web server either (everything else I have thrown at it works great)

[!--quoteo(post=353576:date=Mar 10 2006, 05:26 AM:name=lessthanthree)--][div class=\'quotetop\']QUOTE(lessthanthree @ Mar 10 2006, 05:26 AM) [snapback]353576[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]
<?php
//Generic form data parser
// Begin HTML page and field table
echo "<html><head><title>Check Form</title></head><body><table cellpadding=20 border=1>";
echo "<tr><td><b>Name</b></td><td><b>Value</b></td></tr>";
// For each $_POST value
foreach ($_POST as $key => $value)
{ // Print the key in the first column
    print "<tr><td>" . $key . "&nbsp; </td>\n";
    print "<td>";
    
    // If the field is an empty array, parse it
    if (is_array($value))
    {
        foreach ($value as $selkey => $selvalue)
        {
            print $selkey . " : ". $selvalue ."&nbsp; <br />";
        }
    }
    else
    {
        // Else (not array) just print the value
        // in second column
        print $value . "&nbsp;";
    }
print "</td></tr>\n";
}
print "</table></body></html>";
?>
[/code]

worked absolutely fine for me.

try placing

[code]
<form method='post'>

<input type='text' name='test1' /><br />
<Input type='text' name='test2' /><br />
<input type='text' name='test3' /><br />
<input type='submit'>

</form>
[/code]

directly under the handler in handler1.php

load the page up and fill out the form. If you get it OK from there something's going wrong between your form and the handler page. Have you definitely set the action to the correct handler?
[/quote]
Also, I just tried viewing the page source; all I get is the HTML!

i.e.
<html>
...
<body>
Name
Value
</tr></table></html></body>

It is ignoring everything after the foreach()

even if I put a print"hello world"; after the foreach() it will not display hello world

This is crazy!



[!--quoteo(post=353574:date=Mar 10 2006, 05:20 AM:name=DarrenFinch)--][div class=\'quotetop\']QUOTE(DarrenFinch @ Mar 10 2006, 05:20 AM) [snapback]353574[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi,

I know I should find some more up to date material - but getting this problems is one way of REALLY understanding the code!

I have been following PHP 4 weekend crash course, and I cannot for the life of me get this to work.

If I create a form and $_POST to say handler.php
handler.php contains
<?php phpinfo() ?> // this works - if I scroll down to the variables I can see all the input from the form

however, if I change the form to $_POST to handler1.php, which contains
<?php
//Generic form data parser
// Begin HTML page and field table
echo "<html><head><title>Check Form</title></head><body><table cellpadding=20 border=1>";
echo "<tr><td><b>Name</b></td><td><b>Value</b></td></tr>";
// For each $_POST value
foreach ($_POST as $key => $value)
{ // Print the key in the first column
print "<tr><td>" . $key . "&nbsp; </td>\n";
print "<td>";

// If the field is an empty array, parse it
if (is_array($value))
{ foreach ($value as $selkey => $selvalue)
{ print $selkey . " : ". $selvalue ."&nbsp; <br />";}
} else { // Else (not array) just print the value
// in second column
print $value . "&nbsp;";
}
print "</td></tr>\n";
}
print "</table></body></html>";
?>

All I get is the HTML header

Can anyone help please ?
[/quote]
Andy,

Am using Abyss web server
form is .html file parsing into handler1.php

I found the error (just), the book is incorrect!
(rather embaraased that I did not spot it sooner!)

The form uses $_POST to post the info on the server, and php script was also using the $_POST method (i..e not $_GET)

this works now, and I can go home happy!

Many thanks



[!--quoteo(post=353629:date=Mar 10 2006, 09:59 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Mar 10 2006, 09:59 AM) [snapback]353629[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Two questions:

#1 - are you actually saving your work as a .php file rather than as a .html file?

#2 - are you testing this on a live server or just in some editor preview mode?
[/quote]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.