Jump to content
samporras

Undefined Index Error

Recommended Posts

Hi guys.

 

I haven't worked too much with PHP and am coming up on an error that I can't fix. I just installed and configured PHP on my pc running windows vista sp1 (IIS7). I've got FastCGI installed and configured and php sites show up perfectly. However, a page on a site that i'm hosting here at TCH is not working locally on my machine (it works on TCH's server :) ).

 

I get the following error message:

 

PHP Notice: Undefined index: userFirstName in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 4 PHP Notice: Undefined index: userLastName in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 5 PHP Notice: Undefined index: email in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 6 PHP Notice: Undefined index: areaCode in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 7 PHP Notice: Undefined index: phonePrefix in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 8 PHP Notice: Undefined index: phoneSufix in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 9 PHP Notice: Undefined index: comments in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 10 PHP Notice: Undefined index: submit in C:\inetpub\wwwroot\LandviewRealty\contact.php on line 13

 

below is the code that the error is referencing and I can not see what I am doing wrong:

 

>//declare variables and assign values
$firstName = $_REQUEST["userFirstName"];
$lastName = $_REQUEST["userLastName"];
$email = $_REQUEST["email"];
$areaCode = $_REQUEST["areaCode"];
$phonePrefix = $_REQUEST["phonePrefix"];
$phoneSufix = $_REQUEST["phoneSufix"];
$comments = $_REQUEST["comments"];
$errorMessage = '';

 

The only thing that I can think of is that I am running PHP version 5.2.8 and my site on TCH is running 5.2.5. I don't think this attributes to what is going on but could it be possible? I've also already checked to make sure that the variables referenced are using the same case within my html code.

 

Thanks in advance for your help!

 

Sam

Share this post


Link to post
Share on other sites

This error means that the values you are seeking (i.e. userFirstName, userLastName etc) do not exist in the $_REQUEST array. How are you sending data? Try this at the top of your code:

 

>print_r($_REQUEST);

 

that will print out the $_REQUEST array and show you what keys have what values (if any).

 

Are you posting from a form to this script? If so you need to verify the names of your input fields in the form and ensure they match the keys you are seeking in the $_REQUEST array

 

I would also use the $_POST array instead of the $_REQUEST array if you are getting data posted from a form. $_REQUEST is a combination of $_POST and $_GET and $_GET values can be set by anyone, so it would be more secure using $_POST if you are posting.

Share this post


Link to post
Share on other sites
>print_r($_REQUEST);

 

that will print out the $_REQUEST array and show you what keys have what values (if any).

 

Thanks OJB. I will update my code to use a $_POST array.

 

I think there is something wrong with the configuration of php on my local machine. The code works fine on the TCH servers. I attempted to use the print_r() function that you provided and it appears to be completely ignoring that statement as well as some other simple php code that I know should work (for example: <? echo date("Y"); ?> )

 

I used the following instructions to install and configure PHP on IIS7

 

http://learn.iis.net/page.aspx/246/using-f...ions-on-iis-70/

 

Any suggestions or changes that I need to make to my php.ini file??

Share this post


Link to post
Share on other sites

some PHP versions are fussy with using shorttags

 

make sure your:

 

<? echo date("Y"); ?>

 

is actually

 

<?php echo data('Y'); ?>

 

Also, if you are running on your local machine there is no need to use IIS (which is very complicated), unless of course you have a windows box at TCH

 

Just use apache, download XAMPP as that has PHP, MySQL, Apache and a bunch of other things bundled in to it and it has a nice simple to use installer. The majority of boxes at TCH are linux boxes, hence use apache, so use apache instead on your home machine unless as I say you have an IIS machine here.

Share this post


Link to post
Share on other sites
Also, if you are running on your local machine there is no need to use IIS (which is very complicated), unless of course you have a windows box at TCH

 

Just use apache, download XAMPP as that has PHP, MySQL, Apache and a bunch of other things bundled in to it and it has a nice simple to use installer. The majority of boxes at TCH are linux boxes, hence use apache, so use apache instead on your home machine unless as I say you have an IIS machine here.

 

Thanks OJB.

 

I ended up installing Apache. When I have time, I will go back and look through the original configuration of php (compare the two php.ini files) and see what the issue was. For now I have a solid working local environment.

 

One question with the XAMPP install. Is there any way to configure apache to use something other than port 80 or 1443? I played around with the configuration file, but had no luck.

 

 

Thanks again for all your help.

 

Sam

Share this post


Link to post
Share on other sites

As far as I know, this is how to do it...

Look in your Apache folder for httpd.conf (might be in the "conf" subdir).

Edit the file in a text editor and search for the line:

Listen 80

 

Change it to whatever port you like, then restart Apache. Or, if you are wanting to make the server accessible to the Internet on a non-standard port, if you have a router then just port map whatever external port you like to the internal port of 80 on the server. That way locally you can access it normally, and only when accessing from outside do you have to use the non-standard port.

 

Oh - and regarding the initial error you were getting, it looks like just a warning and not an actual error. Chances are your PHP install is showing verbose errors to the browser whereas the install here wouldn't do that by default (would get messy really quick!) I think it's just warning you that when you are running the script, because you don't check if the variable exists and are just assigning it, it's warning you the variables are empty. If you actually posted to the script, it wouldn't say that. Try it. It's good to have that enabled for testing scripts to look for all possible glitches and warnings before posting it online.

Edited by TheCanadian

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.


×
×
  • Create New...