Jump to content
oneoleguy

$_POST

Recommended Posts

Hello,I made an earlier post about an IF test and found that the $fields = $_POST['fields']; was missing.I have gotten a forms generating program and found that each program has bugs in them. I figured that someone got angry with the purveyors of the software and removed all the $_POST statements.I've been replacing them when I find them, but I have 2 that aren't fixed by simply placing a $variablename = $_POST['variablename']; in the PHP file.I begin to believe that defining a variable as being passed in a POST statement from another file may have different forms for different variable types.For instance $variablename = $_POST['variablename']; seems to work fine for a TEXT variable, but not for a Radio Button.I've looked in the PHP Tutorial but it doesn't go into this level of detail. I've searched 2 PHP Reference Manuals and have been unable to find adequate examples of the $_Post command.Could someone tell me the syntax for each of the variable types used in passing information from a POST statement in one program to another program?One Ole Guy

Share this post


Link to post
Share on other sites

It should work just fine for radio buttons.Given the form:<form action="file.php" method="post"><input type="radio" name="obj" value="Value1" /><input type="radio" name="obj" value="Value2" /><input type="radio" name="obj" value="Value3" /></form>You can output the incoming data of it by writing:echo $_POST['obj'];or assign it to a variable:$myvar = $_POST['obj'];Be sure the method="post". If the method="get" then use $_GET['obj'].

Share this post


Link to post
Share on other sites

Hi Ingolme,You were the person who help me last time and I thank you once again for that help. I'm continuing along with the same set of programs.These are today's error messages:Notice: Undefined index: radio in /home/vh1176/www/billsplace.us/fg/process2.php on line 173Notice: Undefined index: active in /home/vh1176/www/billsplace.us/fg/process2.php on line 174Notice: Undefined index: select in /home/vh1176/www/billsplace.us/fg/process2.php on line 175This is what those lines look like:Line 173 $radio = $_POST['radio'];Line 174 $active = $_POST['active'];Line 175 $select = $_POST['select'];If I missed copying a line, please excuse me. There is no error message generated for this code snippet from the calling program:

echo "<form action='process2.php' method=post>";for($i=0;$i<sizeof($name);$i++){//If its a Drop Down Selectif($type[$i]=="select"){echo "<table width=90%>";echo "<td><td colspan=2 class='small'>Fields for Drop Down Select: '".$name[$i]."'</td></tr>";for($j=0;$j<$size1[$i];$j++){echo "<tr><td>Option ".($j+1)."</td><td><input type=text name='select[$i][$j]' size='20'></td></tr>";}echo "<input type=hidden name='active[$i]' value='".$j."'>";echo "</table>";echo "<br><br>";}//If its a radio buttonif($type[$i]=="radio"){echo "<table width=90%>";echo "<td><td colspan=2 class='small'>Options for Radio Button: '".$name[$i]."'</td></tr>";for($j=0;$j<$size1[$i];$j++){echo "<tr><td>Option ".($j+1)."</td><td><input type=text name='radio[$i][$j]' size='20'></td></tr>";}echo "<input type=hidden name='active[$i]' value='".$j."'>";echo "</table>";echo "<br><br>";}}for($i=0;$i<sizeof($name);$i++){echo "<input type='hidden' name='name[$i]' value='".$name[$i]."'>";echo "<input type='hidden' name='type[$i]' value='".$type[$i]."'>";echo "<input type='hidden' name='size1[$i]' value='".$size1[$i]."'>";echo "<input type='hidden' name='size2[$i]' value='".$size2[$i]."'>";echo "<input type='hidden' name='required[$i]' value='".$required[$i]."'>";}echo "<input type=submit value='next'>";}?> <!-- end stuff -->

There is no complaint in the CALLED program for these statements:$name = $_POST['name'];$type = $_POST['type'];$size1 = $_POST['size1'];$size2 = $_POST['size2'];$required = $_POST['required'];However there is for these:$radio = $_POST['radio'];$active = $_POST['active'];$select = $_POST['select'];Do you have any idea what is wrong? If I remove the $active = $_POST statement, 2 or 3 other error message are printed about undefined index or something: active ?I add it I get an error message, I remove it I get an error message. I can't get an even break!Go Figure!One Ole Guy

Share this post


Link to post
Share on other sites

name='active[$i]' and name='radio[$i][$j]' look kind of strange to me. I'm not sure how those variables would be read.Somebody else would have to help you with that.

Share this post


Link to post
Share on other sites

Could you post the whole pages script, a link, and any other comments about what's happening? I am having trouble understanding what's wrong.

Share this post


Link to post
Share on other sites

CloneTrooper,The forms generator can be found at:billsplace.us/fg/Put that in your browser address window and the forms generator will start automatically. The error occurs on the 3rd page.I don't know if you will be able to view the source code there, if not I will post it in it's entirity here or place it at some common URL where it can be read.If the Forum will allow uploads, I will upload it and pm it to you.Whichever works.One Ole Guy

Share this post


Link to post
Share on other sites

Could the problem be the version of PHP on my server? I'm not trying to execute on my own PC, but on the server hosting my domain.Maybe I should just sleep on it for a while and see what happens.One Ole Guy

Share this post


Link to post
Share on other sites

Ok, I downloaded it... and your saying that the program is broken?I think so... I had to manually change the $_POST for my test example!Can you still go through and use it? or does it just crash when you are making it?

Share this post


Link to post
Share on other sites

I was given another PHP application at the same time as this one. I was testing it today and didn't realized that it had been printing error messages.Neither application's programs crash, but not all their functions work.I've written to support at my host to see if there is special code I need to add to the PHP file. They're not real responsive, so it could be a few days.One Ole Guy

Share this post


Link to post
Share on other sites

Lol I think I know why the original scripts you got didn't have the $var = $_POST['var'] things - it was because it expected register_globals to be on. That means that all $_POST vars are automatically initialised to their own variable. So if you had $_POST['var'], then with register_globals you could access it with $var. Try turning register_globals on and see what happens.

Share this post


Link to post
Share on other sites

Thanks Synook,I'm not a PHP programmer (though I'll be closer to being one after debugging these applications) and went to the PHP tutorial. There I did a search on: 'register_globals' so I went the W3Schools PHP Tutorial couldn't find any reference to it.Could you give me the syntax for that command and tell me where to put it in the program?Thanks again,One Ole GuyPS If any of you are interested, my host's support person wrote and said:When visiting http://billsplace.us/fg/, there is no error info.Can you please send us more detailed info about this?I then executed the scripts and copied what was displayed on the screen and emailed it back to her. Would anyone like to see the pages I copied?

Share this post


Link to post
Share on other sites

Hey Synook,I may be on the path to discovery! When visiting the site of the author of the other application, they had a reference to another site for PHP. It was PHP.netThere I did a search for register_globals in their online documentation and I found a reference to it.It seems that I may need to create a PHP.ini file! Well, that's interesting!I'll do more research and let you know what I find. One Ole Guy

Share this post


Link to post
Share on other sites

Your host already has a php.ini file. And most likely, they're not going to allow you to tamper with it.What you can do is to try the ini_set() function to turn register_globals off. If you fail, ask your host to turn that php.ini setting off for you, or at least tell you how you could do it yourself.P.S. http://php.net is the de facto PHP website. It's THE website of PHP. The place where it all originates from, and where the best documentation for PHP is situated. When in doubt, RTFM.

Share this post


Link to post
Share on other sites

No wait, I was thinking One Old Guy may have to turn register_globals on, because all of the $_POST vars seem to be referenced by their $keys in the original script. That was why he was having to write $var = $_POST['var']; akll over the place.

Share this post


Link to post
Share on other sites

Synook,If you follow the link in my last post, the first thing about register_globals that you'll see is a warning:This feature is DEPRECATED and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.I've reported my other application to the author (who is online) because it's programs are doing the same thing. Perhaps they will be able to tell me what's wrong with their programs or my hosts PHP installation and I can apply that fix tto these programs?I've discovered another issue that may point to problems with my host's PHP installation! Then again I don't know that for sure either, but I've written their support about it.I downloaded the PHP Users Manual from PHP.NET. In the "What is PHP" Chapter (in "Getting Started", "Introduction") is a simple example of PHP code. I copied it, uploaded it to my domain and found that it doesn't run. This is the simple code:

<html>   <head>	   <title>Example</title>   </head>   <body>	   <?php 	   echo "Hi, I'm a PHP script!"; 	   ?>   </body></html>

Anyway I uploaded it to billsplace.us/temp/hi.html and only get a blank screen when I go to it. I sent the host's support people a message that I couldn't execute it. Waiting for a response.As I've said, I'm not a PHP programmer and all these mysteriously caused problems isn't making it any more likely for me to be one.I tried to install PHP 5.2.5 for windows on my PC last night, but it appears to need an HTTP type server on my PC so I downloaded Apache versions 2.0.63 and 2.2.8, but I haven't figured out how to install either of them, yet. I know I can only use 1 version of Apache 2, I just downloaded 2.0.63 before I realized I'd clicked on the wrong link. I'm not deleting it just yet! Then there's that mess of their use of PGP, which appears to be out of date and no longer supported. Where do you get a current copy?I looked at PgnuGP (a replacement for PGP), but I don't have a warm and fuzzy about it either. They have a .sig file with it. The file is some sort of binary file and there aren't any instructions on how to use it. After all that, last night, I just went to bed.I'll probably start trying to install PHP and Apache in a week or too. In the mean time I'm just waiting to see if anyone comes up with solutions to the programs which aren't working correctly.

Share this post


Link to post
Share on other sites

If you want to install them easily, http:apache2triad.net/ It'll do all the icky fun stuff for you.

Share this post


Link to post
Share on other sites

Thanks Jhecht,I downloaded that file and ran it. It copied thousands of file from itself to my hard drive.It then booted my PC.I thought this is sweet!!!!!!!!!!!When the PC re-booted, I couldn't find an Icon on my desktop nor a menu item on my Start/Program List for Apache.It seems that I need to compile Apache. Which requires me to download Visual C++ and Visual SDK for C++. And I haven't gotten any farther, I'm downloading the SDK for the second time and oh, poo! It failed a second time.These were free applications, what a mess!One Ole Guy

Share this post


Link to post
Share on other sites

You shouldn't have to do anything. The install directory(unless you changed it) should be C:\apache2triad\htdocs\ Put your files into there and type in http://localhost/ and you should be good.

Share this post


Link to post
Share on other sites

O.K. Now I know something.I'm not real sure what that is, but the forms generator application I've been having troubles with; worked perfectly fine with my new Apache Server on my PC.I haven't a clue what the PHP.ini file contains, but the application ran every program without error.I think this must mean that the reason it didn't run on my Hosts Server is because of some change they've made to this .ini file?Does that sound correct?One Ole Guy

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...