darrenfinch Posted March 10, 2006 Share Posted March 10, 2006 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.phphandler.php contains<?php phpinfo() ?> // this works - if I scroll down to the variables I can see all the input from the formhowever, 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 . " </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 ." <br />";} } else { // Else (not array) just print the value // in second column print $value . " "; } print "</td></tr>\n"; } print "</table></body></html>";?>All I get is the HTML headerCan anyone help please ? Quote Link to comment Share on other sites More sharing options...
lessthanthree Posted March 10, 2006 Share Posted March 10, 2006 [code]<?php//Generic form data parser// Begin HTML page and field tableecho "<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 valueforeach ($_POST as $key => $value){ // Print the key in the first column print "<tr><td>" . $key . " </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 ." <br />"; } } else { // Else (not array) just print the value // in second column print $value . " "; }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.phpload 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 Link to comment Share on other sites More sharing options...
darrenfinch Posted March 10, 2006 Author Share Posted March 10, 2006 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 $_POSTI tried it without the $_ and I still get the sameand 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 tableecho "<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 valueforeach ($_POST as $key => $value){ // Print the key in the first column print "<tr><td>" . $key . " </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 ." <br />"; } } else { // Else (not array) just print the value // in second column print $value . " "; }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.phpload 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] Quote Link to comment Share on other sites More sharing options...
lessthanthree Posted March 10, 2006 Share Posted March 10, 2006 The form method should still be set to POST if that's what you mean.I think i might have misunderstood your post though. Quote Link to comment Share on other sites More sharing options...
darrenfinch Posted March 10, 2006 Author Share Posted March 10, 2006 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 worldThis 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.phphandler.php contains<?php phpinfo() ?> // this works - if I scroll down to the variables I can see all the input from the formhowever, 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 . " </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 ." <br />";} } else { // Else (not array) just print the value // in second column print $value . " "; } print "</td></tr>\n"; } print "</table></body></html>";?>All I get is the HTML headerCan anyone help please ?[/quote] Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 10, 2006 Share Posted March 10, 2006 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 Link to comment Share on other sites More sharing options...
darrenfinch Posted March 10, 2006 Author Share Posted March 10, 2006 Andy,Am using Abyss web serverform is .html file parsing into handler1.phpI 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.