• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

PHP Errors

In the code below, how can edit it so if the wr5 field is empty, it will not give ANY errors when the submit button is clicked?
if (empty($_POST['wr5'])) {
		$errors[] = 'Do not forget to enter who is responsible for sent date change.';
	} else {
		$wr5 = $_POST['wr5'];
		}
		
if (empty($errors)) {

Open in new window

0
wantabe2
Asked:
wantabe2
  • 2
1 Solution
 
russianryebreadCommented:
I'm assuming that you want to clear the entire error array if the wr5 variable from POST doesn't have a value...  If you are trying to do that you can simply unset the array like this:


if (empty($_POST['wr5'])) {
	unset($errors)
} else {
	$wr5 = $_POST['wr5'];
}
		
if (empty($errors)) {

Open in new window

0
 
wantabe2Author Commented:
If I do that I get the undefined variable error in php
0
 
russianryebreadCommented:
That is just a notice, and I am not sure what the rest of your code looks like, or what line it says is throwing the error, but you should be able to fix that by putting the following code as the last line of what is posted.  I didn't test it, but it should clear up your notice.  If there is code following the snippet you posted that is looking for a value in $errors, the notice will just move down.  You can either change the code, turn off the notices, or reset the error array like so: $errors = array() right under the unset($errors).  That would basically reset your $error var as an empty array.  Without seeing the full context of what we are working with, it's difficult to advise you.
if(!isset($errors)) {

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now