Solved

error log errors - undefined index

Posted on 2011-02-21
3
885 Views
Last Modified: 2012-05-11
[Sat Feb 05 10:03:02 2011] [client 76.168.200.119] PHP Notice:  Undefined index:  CheckBRKD in /home/derm/history/formpdf_history.php on line 482, referer: https://midvalleydermatology.com/history/historyform.php

line 482:
$pdf->Cell(10,5,$_POST['CheckBRKD'],1,0,'L');
corresponding form field:
<input name="CheckBRKD" type="checkbox"  value="Yes" />
0
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 34948012
You not checking anything.  I can submit a blank form and see a page full of errors.  What I normally do on forms is set a default value and then let the POST replace it if the POST value exists.  Or set a default value if the POST isn't set, otherwise use the POST value.
// this way...
$fname = "";
if (isset($_POST['fname'])) $fname = $_POST['fname'];

// or this way...
if (!isset($_POST['fname'])){$fname = "";} else {$fname = $_POST['fname'];}

Open in new window

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 34951360
Unchecked checkboxes are different from empty text input controls.  They are not present at all in the POST array.  They are not only empty, they are simply undefined.

It's fairly axiomatic in programming that you want to accept only known good values from external sources.  So if you think the input control named CheckBRKD should have a value of "yes" (or something else) you almost certainly want to test $_POST["CheckBRKD"] to see if it is set at all, and then test it to see if it contains an expected and acceptable value.  Simply using an element of $_POST without checking is a way to be certain that catastrophe is not left to chance.

You might consider using the ternary operator to set a default value for this sort of checkbox field.

$c = (isset($_POST["CheckBRKD"])) ? "yes" : "no";

In that line of code you choose the value for the variable $c.  It is safer to do it this way than to rely on the contents of the external variable in the POST array.
0
 

Author Closing Comment

by:phillystyle123
ID: 34975716
thanks experts!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

726 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