Solved

error log errors - undefined index

Posted on 2011-02-21
3
875 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 82

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

19 Experts available now in Live!

Get 1:1 Help Now