Solved

error log errors - undefined index

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

728 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