?
Solved

PHP Errors

Posted on 2011-05-09
3
Medium Priority
?
166 Views
Last Modified: 2012-08-14
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
Comment
Question by:wantabe2
  • 2
3 Comments
 
LVL 3

Expert Comment

by:russianryebread
ID: 35723293
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
 
LVL 15

Author Comment

by:wantabe2
ID: 35723560
If I do that I get the undefined variable error in php
0
 
LVL 3

Accepted Solution

by:
russianryebread earned 2000 total points
ID: 35723738
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question