PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old September 30th, 2003, 05:46 PM
mberry mberry is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: denver colorado
Posts: 4 mberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 30th, 2003, 06:17 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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

Reply With Quote
  #3  
Old October 1st, 2003, 12:51 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
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.

Reply With Quote
  #4  
Old October 1st, 2003, 07:03 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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:
while(list($k,$v)=each($_POST)){
    $
$k=$v//Yes, that's two dollar signs



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.

Reply With Quote
  #5  
Old October 2nd, 2003, 09:59 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
In that case why not try:
PHP Code:
 extract(array_merge($_POST,$_GET)); 

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

Reply With Quote
  #6  
Old October 2nd, 2003, 10:06 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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!

Reply With Quote
  #7  
Old October 2nd, 2003, 10:18 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
No problem at all.

Reply With Quote
  #8  
Old October 2nd, 2003, 04:22 PM
mberry mberry is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: denver colorado
Posts: 4 mberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
here is some code from the form:

<form method="POST" action="hormone_eval_send.php" name="Form1">

<font face="Arial">First Name:&nbsp;&nbsp;
<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

Reply With Quote
  #9  
Old October 2nd, 2003, 04:28 PM
mberry mberry is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: denver colorado
Posts: 4 mberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #10  
Old October 2nd, 2003, 06:18 PM
mberry mberry is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: denver colorado
Posts: 4 mberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking FIXED

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

Reply With Quote
  #11  
Old October 2nd, 2003, 08:12 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
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.

Reply With Quote
  #12  
Old July 22nd, 2004, 07:08 PM
fozzyuw fozzyuw is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 fozzyuw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 15 sec
Reputation Power: 0
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

Reply With Quote
  #13  
Old July 22nd, 2004, 07:18 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
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:
if ( (isset($_POST['display'])) && (count($_POST['display'])>0) ) {
  
/* now start touching the array indexes */
  
foreach ( $_POST['display'] as $array_index => $array_value ) {
     
// output goes here
  
}


Reply With Quote
  #14  
Old July 22nd, 2004, 07:40 PM
fozzyuw fozzyuw is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 fozzyuw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 15 sec
Reputation Power: 0
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

Reply With Quote
  #15  
Old July 22nd, 2004, 08:34 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
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:
<?php
 
if ( isset($_POST) ) {
  
printf('$_POST is set, is an %s, and contains %s items.'gettype($_POST), cou
nt
($_POST));
 } else {
  
/* notice that we never land here? */
  
print '$_POST is not set!'
 }
?>
<form action="post.php" method="post">
<input name="test1" type="checkbox" value="1">
<input name="test2" type="checkbox" value="1">
<input type="submit">
</form>

Reply With Quote
  #16  
Old July 23rd, 2004, 11:12 PM
rtgo4 rtgo4 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)