|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
php Undefined variable error from form to script
recently our Linux/apache server's harddrive crashed, so i moved our website to a windows server. All the forms on the site are html forms that POST to a .php script to be e-mailed. these all worked fine on the Linux box, but now i get this error on my windows server that is in use untill the linux server is back up:
Notice: Undefined variable: message in c:\inetpub\wwwroot\html\hormone_eval_send.php on line 18 and it does that for all the variables from the form. so i have a page full of errors. I read through the code and made sure i didnt need to change anything in it to run on windows. i couldnt find anything wrong with it. is there something i could have missed in the php.ini? or do i need to POST the variables in some other manner? Thanks ahead for any help ![]() |
|
#2
|
|||
|
|||
|
What versions are running on each box?
You may have register_globals set to "ON" on one of the boxes, and "OFF" on the other. What's the code you have right now? Can you post it.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
I'm about 99% sure it is a register_globals issue. Turn it on and see if you still have the same errors.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#4
|
||||
|
||||
|
This post made me think about the fact that some people (on shared hosting, for example) don't have the ability to modify their register_globals setting. And I don't believe that's one you can modify at runtime. A quick way around it if you've got to do a quick conversion is to stick the following at the top of your code:
PHP Code:
This loops through the $_POST array and, for each key in the array, sets a variable with the name of that key to the associated value, effectively doing what turning register_globals on would do for you. I personally recommend coding in such a way that you don't need this trick, scoping your variables appropriately for the sake of readability, but if you're in a jam and have to get this up but can't change your register_globals settings, this might be a workable temporary fix. |
|
#5
|
|||
|
|||
|
In that case why not try:
PHP Code:
This creates a variable for each key in the post and get arrays. You can do this with the cookies array and session array if you like. Also, if you don't have access to php.ini and you do have access to .htaccess you can add this line to it: #Turn off register globals php_value register_globals 0 #Turn on register globals php_value register_globals 1 |
|
#6
|
||||
|
||||
|
Learn something new every day. I had seen extract() but never looked to see what exactly it did. And I sure didn't know you could control register_globals using .htaccess files. Thanks for the info!
|
|
#7
|
|||
|
|||
|
No problem at all.
|
|
#8
|
|||
|
|||
|
here is some code from the form:
<form method="POST" action="hormone_eval_send.php" name="Form1"> <font face="Arial">First Name: <input type="text" name="First_Name" size="20"> </form> here is some from the php script: echo("<html><body><font face='Courier'>Sending"); $first_name = $HTTP_POST_VARS["First_Name"]; i tried to set the register_globals to On and it did not work. I will try the other code suggestions Thanks ![]() |
|
#9
|
|||
|
|||
|
I tried both the:
while(list($k,$v)=each($_POST)){ $$k=$v; //Yes, that's two dollar signs } and: extract(array_merge($_POST,$_GET)); they both came up with the same errors I had before. just seems a bit odd. Thanks for you help ![]() |
|
#10
|
|||
|
|||
|
Found a solution. I uninstalled IIS and installed Apache and PHP. Now it seems to run great. guess it just doesnt like IIS.
Thanks for all your help ![]() |
|
#11
|
|||
|
|||
|
I can blame IIS for many many problems, but I don't see how IIS could have been causing the current problem.
It is possible your last PHP installation was problematic, but nonetheless you have it working so enjoy. |
|
#12
|
|||
|
|||
|
It seems, I now have this problem.
I'm running the latest apache 1, php 4.3.8, and mysql4.0. This is on my 'testbox' which is winXP. I have a select form called "display". My PHP script on that page does a switch/case statement based of the value of the "display" variable. I turned my registered_global variables to on in the php.ini file. That didn't work. I then tryed to use $HTTP_POST_VARS["dispaly"] but I get "Undefined index", which I assume is the same reason. .... Ok, nevermind. If I submit my "display" form once, the problem goes away. But upon first view of the webpage it gives me the "undefined variable". How can I have this variable set to null right off the bat, if the form hasn't been used yet? Basically, any idea why this is happening and what is a good suggestion to fix it? Cheers, Fozzy |
|
#13
|
|||
|
|||
|
1 - Try to use $_POST instead of $HTTP_POST_VARS
2 - Check for the existance of variables and especially array indexes before usage: PHP Code:
|
|
#14
|
|||
|
|||
|
Thanks,
I tried using $_POST["display"] but I got... "Undefined index". I used the "isset()" code with an if/else statement to get what I wanted. originally I had it set such that if the variable wasn't set it would trigger the 'default' part of switch but I'm thinking that might be because of part of the 'magic' behind global variables. If someone could explain what $_POST will return if the variable has never been used yet? (Freshly loaded page) Would it be null? Cheers, Fozzy |
|
#15
|
|||
|
|||
|
If a form was not posted then $_POST should be an empty array.
In other words, if there was no form posted to the page $_POST still exists, but it would be empty. See the following code: PHP Code:
|
|
#16
|
||
|