AdRock Posted March 8, 2008 Share Posted March 8, 2008 I am trying to make my code free of errors and have come across a problem If i set the php.ini error reporting to all i get these strange errors but if i disable error reporting, it works These are the errors if i try submitting an empty form [sat Mar 08 17:07:17 2008] [error] PHP Notice: Undefined index: password1 in d:\\Apache\\htdocs\\my car share\\pages\\inc\\register.inc.php on line 33 [sat Mar 08 17:07:17 2008] [error] PHP Notice: Undefined index: email2 in d:\\Apache\\htdocs\\my car share\\includes\\functions.php on line 127 [sat Mar 08 17:07:17 2008] [error] PHP Notice: Undefined index: password2 in d:\\Apache\\htdocs\\my car share\\includes\\functions.php on line 127 and if i enter some info in the form and submit for example postcode [sat Mar 08 17:27:48 2008] [error] PHP Notice: Undefined index: password1 in d:\\Apache\\htdocs\\my car share\\pages\\inc\\register.inc.php on line 33 [sat Mar 08 17:27:48 2008] [error] PHP Notice: Undefined index: postcode in d:\\Apache\\htdocs\\my car share\\includes\\functions.php on line 127 [sat Mar 08 17:27:48 2008] [error] PHP Notice: Undefined index: email2 in d:\\Apache\\htdocs\\my car share\\includes\\functions.php on line 127 It seems to randomly change which variables have an undefined index Here is my code with the variables <?php if(isset($_POST['register'])) { $register = $_POST['register']; } function check_form() { //set up some global variables to be passed between validation function and form global $_POST, $error, $print_again, $register, $message; global $first_name, $last_name; global $houseno, $street, $town, $county, $postcode, $telephone; global $email1, $email2, $username, $password1, $password2; //variables for checking the user's name $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; //variable for checking the user address and telephone $houseno = $_POST['houseno']; $street = $_POST['street']; $town = $_POST['town']; $county = $_POST['county']; $postcode = $_POST['postcode']; $telephone = $_POST['telephone']; //variables for checking the user's email $email1 = $_POST['email1']; $email2 = $_POST['email2']; //varaibles for checking the user login credentials $username = $_POST['username']; $password1 = $_POST['password1']; $password2 = $_POST['password2']; //set the error to false $error['first_name'] = false; $print_again = false; and here is the error in the functions.php it's complaining about but i don't think it has anything to di with this function error_bool($error, $field) { if($error[$field]) { print("style=\"background-color:#FBEC87\""); } else { print("style=\"background-color:white\""); } } Any ideas? Link to comment https://forums.phpfreaks.com/topic/95083-undefined-indexes/ Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 "If i set the php.ini error reporting to all i get these strange errors but if i disable error reporting, it works" i suggest not turning on all errors, or you'll see this all the time. the other alternative is to actually define every index and that would be a pain. there are error settings between ALL and NONE. Link to comment https://forums.phpfreaks.com/topic/95083-undefined-indexes/#findComment-487050 Share on other sites More sharing options...
Sulman Posted March 8, 2008 Share Posted March 8, 2008 Just out of interest what are the drawbacks (in server overheads etc) of not defining vars vefore using them? Link to comment https://forums.phpfreaks.com/topic/95083-undefined-indexes/#findComment-487057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.