have created an add record form (.PHP) that has 3 checkboxes. The checked value = Y, the initial state is unchecked. The form is sent to go to a view page in which all the entered data is viewed.
When I preview the form in a browser and check all 3 boxes and submit the form works perfectly; that is the data is entered correctly into the mysql database and the view page becomes visible.
If I preview the form and leave any of the boxes unchecked I get the following error message:
PHP Notice: Undefined index: endemismo in c:\inetpub\wwwroot\fauna_europaea\TMP826889f9hy.php on line 37
PHP Warning: Cannot modify header information - headers already sent in c:\inetpub\wwwroot\fauna_europaea\TMP826889f9hy.php on line 47
endemismo in this case is the name of the checkbox left unchecked.
It might also be worthy noting that the data is entered correctly into the database despite the error message, that is if the check box is checked the corresponding database field receives a "Y" and is blank if not checked.
Any ideas how to fix the error message?
Many thanks
Jim
checkbox/radio button error message PHP
Moderator: General Moderators
This is the code that the error refers to:
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "add_form")) {
$insertSQL = sprintf("INSERT INTO mollusca (parentesis, taxondud, endemismo) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['parentesis'], "text"),
GetSQLValueString($HTTP_POST_VARS['taxondud'], "text"),
GetSQLValueString($HTTP_POST_VARS['endemismo'], "text"));
The error message mentioned above was when field "endemismo" went unchecked. Line 37 corresponds to the GETSQLVALUE....line for endemismo
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "add_form")) {
$insertSQL = sprintf("INSERT INTO mollusca (parentesis, taxondud, endemismo) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['parentesis'], "text"),
GetSQLValueString($HTTP_POST_VARS['taxondud'], "text"),
GetSQLValueString($HTTP_POST_VARS['endemismo'], "text"));
The error message mentioned above was when field "endemismo" went unchecked. Line 37 corresponds to the GETSQLVALUE....line for endemismo
Hmm.
If endemismo is unchecked, then it would have a value of 0, right?
if so, and you have no error checks in place, sql is going to try and insert 0 into the database in the endemismo field.
This is bad. MySQL doesn't like treating 0 as a number. You have to enclose 0 in quotes (single or double, your call) to stop the script from barfing.
Maybe.
Yeah, after reading your first post, this is definately a maybe explanation
If endemismo is unchecked, then it would have a value of 0, right?
if so, and you have no error checks in place, sql is going to try and insert 0 into the database in the endemismo field.
This is bad. MySQL doesn't like treating 0 as a number. You have to enclose 0 in quotes (single or double, your call) to stop the script from barfing.
Maybe.
Yeah, after reading your first post, this is definately a maybe explanation
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Yeah, any radiobutton that is unchecked automatically has a value of 0, so it's not blank, it's just 0 which is as good as blank, but PHP doesn't think it's blank. Even though it is. Which it's not.twigletmac wrote:If endemismo is unchecked then $HTTP_POST_VARS['endemismo'] won't exist and you'll get an error.
*head 'splode*
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK