Solved

error log errors - undefined index

Posted on 2011-02-21
3
878 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
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 108

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 32
File submission to SQL Server 1 38
simplest php form 3 61
PHP get array item with custom id 4 22
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). #…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now