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:
  #1  
Old September 30th, 2003, 05:46 PM
mberry mberry is offline
Registered User
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,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
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
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
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: 17
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
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
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: 17
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
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
No problem at all.

Reply With Quote
  #8  
Old October 2nd, 2003, 04:22 PM
mberry mberry is offline
Registered User
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
Registered User
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
Registered User
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
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
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
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
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
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
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)
 
Join Date: Jul 2004
Posts: 1 rtgo4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help!

I'm getting Undefined Variable outsite of my <form>. I did have problem with a variable in my <form> but after I turned register_globals = On in the php.ini file it fixed that. BUT!! I still get the Undefined Variable error on variable outside my <form>. Can somebody help me?

Thanks so much,
rtgo4

Reply With Quote
  #17  
Old January 14th, 2009, 05:51 AM
borntodeal borntodeal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 1 borntodeal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 24 sec
Reputation Power: 0
I'm having trouble with this code

I read this thread and I am super new to PHP so if I sound green it is because I am.

I have this script I want to use to upload binary files.

I am getting the same undefined variable issue and the register_globals=off.

Can you tell me why this script is not working?

PHP Code:
<?php
if ($action == "upload") {
  
// ok, let's get the uploaded data and insert it into the db now
  
include "open_db.inc";

  if (isset(
$binFile) && $binFile != "none") {
    
$data addslashes(fread(fopen($binFile"r"), filesize($binFile)));
    
$strDescription addslashes(nl2br($txtDescription));
    
$sql "INSERT INTO immersa_files ";
    
$sql .= "(description, bin_data, filename, filesize, filetype) ";
    
$sql .= "VALUES ('$strDescription', '$data', ";
    
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
    
$result mysql_query($sql$db);
    
mysql_free_result($result); // it's always nice to clean up!
    
echo "Thank you. The new file was successfully added to our database.<br><br>";
    echo 
"<a href='main.php'>Continue</a>";
  }
  
mysql_close();

} else {
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
 <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="10000000">
 <INPUT TYPE="hidden" NAME="action" VALUE="upload">
 <TABLE BORDER="1">
  <TR>
   <TD>Description: </TD>
   <TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
  </TR>
  <TR>
   <TD>File: </TD>
   <TD><INPUT TYPE="file" NAME="binFile"></TD>
  </TR>
  <TR>
   <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
  </TR>
 </TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>


The contents of the database connector are:

PHP Code:
<?php
    $db 
mysql_connect("foo""foo""foo");
    
mysql_select_db("foo"$db) or die(mysql_errno() . ": " mysql_error() . "<br>");
?>

Last edited by borntodeal : January 14th, 2009 at 05:54 AM. Reason: Adding info

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > php Undefined variable error from form to script


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap