By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

error on POSTed form

P: n/a
Wm
I'm having a very hard time trying to add an edited listing to mySQL. I'm
breaking this in to two halves, so that each error/problem can [hopefully]
be pinpointed.

The edit form queries mySQL and fills in a form with their existing
information (identical form to the original "Add Me" form, but this time
echo'ing the data currently in mySQL). This part works great. Once they
have edited their information, Submit takes them to a page called save.php.
Now the problems start. Below are my errors, followed by the section of the
code to which they are referring. The errors are all fields where checkboxes
were UNchecked -- the variables that were checked are not cited as errors.

Warning: Undefined index: hair in /home/httpd/httpdocs/html/save.php on line
33
Warning: Undefined index: tv in /home/httpd/httpdocs/html/save.php on line
36
Warning: Undefined index: film in /home/httpd/httpdocs/html/save.php on line
37
Warning: Undefined index: bridal in /home/httpd/httpdocs/html/save.php on
line 39

My code, beginning at line 20, is:
<?PHP
error_reporting (E_ALL);
$firstname = (ucwords(strtolower(trim($_POST['firstname']))));
$lastname = (ucwords(strtolower(trim($_POST['lastname']))));
$city= (ucwords(strtolower(trim($_POST['city']))));
$state= (strtoupper($_POST['state']));
$country= (strtoupper($_POST['country']));
$availability= (addslashes($_POST['availability']));
$experience= (addslashes($_POST['experience']));
$email= (strtolower($_POST['email']));
$website= (strtolower($_POST['website']));
$newpasswd = ($_POST['website']);
$makeup = ($_POST['makeup']);
$hair = ($_POST['hair']);
$wardrobe = ($_POST['wardrobe']);
$print = ($_POST['print']);
$tv = ($_POST['tv']);
$film = ($_POST['film']);
$video = ($_POST['video']);
$bridal = ($_POST['bridal']);
$artistID = ($_POST['artistID']);

FWIW, I have tried the checkboxes both with and without the ( ) around the
$_POST... Do I have to handle anything differently to account for UNchecked
checkboxes, which presumably aren't passed?

Thanx!
Wm



Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
>Do I have to handle anything differently to account for UNchecked
checkboxes, which presumably aren't passed.

These variables are passed but are passed as null or empty values.

Try an function such like is_null($i) or empty($i)

eg

if ((is_null($i)) || (!empty($i))){
.....
}
reference : http://us4.php.net/manual/en/function.empty.php
http://us4.php.net/manual/en/function.is-null.php
-JD

"Wm" <LA*******@hotmail.com> wrote in message
news:3Y**********************@news.easynews.com... I'm having a very hard time trying to add an edited listing to mySQL. I'm
breaking this in to two halves, so that each error/problem can [hopefully]
be pinpointed.

The edit form queries mySQL and fills in a form with their existing
information (identical form to the original "Add Me" form, but this time
echo'ing the data currently in mySQL). This part works great. Once they
have edited their information, Submit takes them to a page called save.php. Now the problems start. Below are my errors, followed by the section of the code to which they are referring. The errors are all fields where checkboxes were UNchecked -- the variables that were checked are not cited as errors.

Warning: Undefined index: hair in /home/httpd/httpdocs/html/save.php on line 33
Warning: Undefined index: tv in /home/httpd/httpdocs/html/save.php on line
36
Warning: Undefined index: film in /home/httpd/httpdocs/html/save.php on line 37
Warning: Undefined index: bridal in /home/httpd/httpdocs/html/save.php on
line 39

My code, beginning at line 20, is:
<?PHP
error_reporting (E_ALL);
$firstname = (ucwords(strtolower(trim($_POST['firstname']))));
$lastname = (ucwords(strtolower(trim($_POST['lastname']))));
$city= (ucwords(strtolower(trim($_POST['city']))));
$state= (strtoupper($_POST['state']));
$country= (strtoupper($_POST['country']));
$availability= (addslashes($_POST['availability']));
$experience= (addslashes($_POST['experience']));
$email= (strtolower($_POST['email']));
$website= (strtolower($_POST['website']));
$newpasswd = ($_POST['website']);
$makeup = ($_POST['makeup']);
$hair = ($_POST['hair']);
$wardrobe = ($_POST['wardrobe']);
$print = ($_POST['print']);
$tv = ($_POST['tv']);
$film = ($_POST['film']);
$video = ($_POST['video']);
$bridal = ($_POST['bridal']);
$artistID = ($_POST['artistID']);

FWIW, I have tried the checkboxes both with and without the ( ) around the
$_POST... Do I have to handle anything differently to account for UNchecked checkboxes, which presumably aren't passed?

Thanx!
Wm


Jul 16 '05 #2

P: n/a
On Sat, 16 Aug 2003 22:44:36 GMT, "Jamie Davison" <ja***@bardavon.org> wrote:
Do I have to handle anything differently to account for UNchecked
checkboxes, which presumably aren't passed.


These variables are passed but are passed as null or empty values.

Try an function such like is_null($i) or empty($i)

eg

if ((is_null($i)) || (!empty($i))){
.....
}


No, they're not passed at all. Only 'successful' controls (as defined in the
HTML specs) are passed. A set variable or array element with a NULL or empty
value is distinct from an unset variable.

Use isset() to determine if the variable has been passed or not.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>form test</title>
</head>
<body>
<form action="" method="get">
<input type="checkbox" name="check1" value="T">
<input type="submit">
</form>
<hr>
<pre>
<?php
print_r($_GET);
?>
</body>
</pre>
</html>

Submit this form with and without the checkbox set; you'll see that check1 is
NOT passed as a null or empty value if the checkbox is unchecked, it simply is
not passed at all.

Checked:

Array
(
[check1] => T
)

Unchecked:

Array
(
)

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.