Solved

error log errors - undefined index

Posted on 2011-02-21
3
883 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 109

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cookie not unsetting 7 27
How to obtain the string from a PHP StdObject ? 6 33
Apache LDAP Authentication 20 27
Checking https returns 301 21 16
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

808 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