WebProgrammerNewb22 Posted October 25, 2010 Share Posted October 25, 2010 Hey guys.. I'm new to the forum and have a quick question about some coding i've been doing for my website. A couple index errors are coming up when I run my code, but I believe it all should be working fine. I am going to paste the code, but also upload the files so that you can understand the problem better. ANY help is greatly appreciated. I am currently making a contact form with validation. I know that using ifempty() is probably the best way, but I am unclear as to how to use it. I have two files, an html containing my form, and a php file containing the following code: //Define Variables $FirstName = $_GET['FirstNameTextBox']; $LastName = $_GET['LastNameTextBox']; $PhoneNumber = $_GET['PhoneNumberTextBox']; $EmailAddress = $_GET['EmailAddressTextBox']; $Address = $_GET['AddressTextBox']; $City = $_GET['CityTextBox']; $State = $_GET['StateDropDownBox']; $Zip = $_GET['ZipTextBox']; $error1='*Please enter a First Name<br>'; $error2='*Please enter a Last Name<br>'; $error3='*Please enter a Phone Number<br>'; $error4='*Please choose a state<br>'; $error5='*Please enter a valid email address<br>'; $day2 = mktime(0,0,0,date("m"),date("d")+2,date("Y")); $day3 = mktime(0,0,0,date("m"),date("d")+3,date("Y")); $day7 = mktime(0,0,0,date("m"),date("d")+7,date("Y")); if($FirstName=="") {echo $error1; exit;} if($LastName=="") {echo $error2; exit;} if($PhoneNumber=="") {echo $error3; exit;} if($State=="") {echo $error4; exit;} if($EmailAddress=="") {echo $error5; exit;} if($State == "NY") { echo "$FirstName $LastName - we will get back to you within 2 days, ie before " .date("d M Y", $day2); exit; } if($State == "NJ") { echo "$FirstName $LastName - we will get back to you within 3 days, ie before " .date("d M Y", $day3); exit; } if($State == "Other") { echo "$FirstName $LastName - we will get back to you within 1 week, ie before " .date("d M Y", $day7); exit; } The following errors come up: Notice: Undefined index: FirstNameTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 14 Notice: Undefined index: LastNameTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 15 Notice: Undefined index: PhoneNumberTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 16 Notice: Undefined index: EmailAddressTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 17 Notice: Undefined index: AddressTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 18 Notice: Undefined index: CityTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 19 Notice: Undefined index: StateDropDownBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 20 Notice: Undefined index: ZipTextBox in C:\Users\Jonny P\Documents\My Web Sites\JMPMySite\AddContact.php on line 21 *Please enter a First Name Again, ANY help is greatly appreciated.. it is for a class, but I have honestly exhasted all my sources to figure out what is wrong. Are my codes correct and all there? Thanks for the help! -WPN [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/ Share on other sites More sharing options...
The Little Guy Posted October 25, 2010 Share Posted October 25, 2010 You have PHP in strict mode, which is why you are getting those errors if(isset( $_GET['FirstNameTextBox'])) $FirstName = $_GET['FirstNameTextBox']; if(isset( $_GET['LastNameTextBox'])) $LastName = $_GET['LastNameTextBox']; if(isset( $_GET['PhoneNumberTextBox'])) $PhoneNumber = $_GET['PhoneNumberTextBox']; if(isset( $_GET['EmailAddressTextBox'])) $EmailAddress = $_GET['EmailAddressTextBox']; if(isset( $_GET['AddressTextBox'])) $Address = $_GET['AddressTextBox']; or place this at the beginning of the file: ini_set('display_errors', '0'); Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126371 Share on other sites More sharing options...
WebProgrammerNewb22 Posted October 25, 2010 Author Share Posted October 25, 2010 I guess I will just use the isset() .. will that register my errors though? I don't see where in that it says if empty, give this error message.. Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126390 Share on other sites More sharing options...
WebProgrammerNewb22 Posted October 25, 2010 Author Share Posted October 25, 2010 would i replace that in my define veriables section? or in my if echo statements.. im still confused to how my errors will show up Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126391 Share on other sites More sharing options...
Pikachu2000 Posted October 25, 2010 Share Posted October 25, 2010 You haven't mentioned the criteria for validation. Are all fields required? Do they have to be checked for specific data types? Etc. Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126393 Share on other sites More sharing options...
The Little Guy Posted October 25, 2010 Share Posted October 25, 2010 I am not 100% what you mean, but if I am correct you can do this: if(isset( $_GET['FirstNameTextBox'])) $FirstName = $_GET['FirstNameTextBox']; else $FirstName = ''; if(isset( $_GET['LastNameTextBox'])) $LastName = $_GET['LastNameTextBox']; else $LastName = ''; if(isset( $_GET['PhoneNumberTextBox'])) $PhoneNumber = $_GET['PhoneNumberTextBox']; else $PhoneNumber = ''; if(isset( $_GET['EmailAddressTextBox'])) $EmailAddress = $_GET['EmailAddressTextBox']; else $EmailAddress = ''; if(isset( $_GET['AddressTextBox'])) $Address = $_GET['AddressTextBox']; else $Address = ''; Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126394 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 I have three functions which look like this... function get_GET($name) { $sret=""; if(isset($_GET[$name])){ $sret=$_GET[$name]; $sret=mysql_real_escape_string($sret); } return $sret; } Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126399 Share on other sites More sharing options...
Psycho Posted October 25, 2010 Share Posted October 25, 2010 No need to get complicated here. Your current code simply uses this validation to check if the GET value was not set or was a null string if($FirstName=="") {echo $error1; exit;} So, just change the way that you set the value. Change this $FirstName = $_GET['FirstNameTextBox']; To this $FirstName = (isset($_GET['FirstNameTextBox'])) ? $_GET['FirstNameTextBox' : ''; Then all your existing code will work as designed. Do the same for all the other values you set from the GET values. Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126409 Share on other sites More sharing options...
WebProgrammerNewb22 Posted October 26, 2010 Author Share Posted October 26, 2010 I'm sorry for not being clear as to what I have to do.. I need error checking that checks for data type, size, and basic format. Required fields are First Name, Last Name, Phone, State, and email. So I would replace the code that you mentioned with the required fields only correct? Quote Link to comment https://forums.phpfreaks.com/topic/216810-data-validation-error-question/#findComment-1126448 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.