TrotskyIcepick Posted December 20, 2010 Share Posted December 20, 2010 I am testing a php form validation script I found on the internet and it is giving undefined index errors on all form input fields, for example : Notice: Undefined index: user_name in C:\www\drupal6\iris\demo.php on line 172 the code here is : <input type="text" name="user_name" value="<?=$fields['user_name']?>" /> This code works fine on my Linux machine but not on Windows with php 5.3.3. I have attached the code for you to examine. Thanks in Advance Andrew [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/222215-dont-understand-undefined-index-errors/ Share on other sites More sharing options...
Adam Posted December 20, 2010 Share Posted December 20, 2010 The Linux/Windows machines will have different levels of error_reporting. All the notice means is that you're trying to use an index within an array that doesn't exist. i.e. $fields['user_name'] doesn't exist. To rectify you need to either explicitly set a value (even if it's an empty string) for $fields['username'] earlier within the code, or check that the index exists before you try to echo it: <input type="text" name="user_name" value="<?php if (isset($fields['user_name'])) echo $fields['user_name']; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/222215-dont-understand-undefined-index-errors/#findComment-1149550 Share on other sites More sharing options...
TrotskyIcepick Posted December 20, 2010 Author Share Posted December 20, 2010 Thanks for the quick reply, I've just set values for the problem variables and now all works fine. Thanks again. Andrew Quote Link to comment https://forums.phpfreaks.com/topic/222215-dont-understand-undefined-index-errors/#findComment-1149555 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.