Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Laler, Help!
I can't figure this one out at all. Look at the warning message on this page. Seems the values are not passed to the array. Code pasted below, let me know if you need more.http://perfectionconstruction.com/L...
the loop:
is_array($_POST["Liked"]);
foreach($_POST["Liked"] as $k)
{
$message .= '<span style="text-decoration:underline; font-weight:bold">Liked</span>' . ': ' .stripslashes($_POST['$k']);
}And it pertains to this html:
Please indicate what you thought of this web site:<br />
<input type="checkbox" name="Liked[ ]" value="Navigation" />It's easy to navigate the links to the pages onthe site.<br />
<input type="checkbox" name="Liked[ ]" value="Validates" />It's well formed and displays nicely in mybrowser.<br />
<input type="checkbox" name="Liked[ ]" value="Informs" />It's informative and/or educational.<br />
<input type="checkbox" name="Liked[ ]" value="Grahics" />It has nice pictures of your work.<br /><br />

I suspect you are getting that error because when you first navigate to that page there is no POST data. So the foreach fails beacause $_POST["liked"] is not an array.
This line is_array($_POST["Liked"]); does absolutely nothing as it is shown. is_array() returns true/false based upon whether the value is an array, but you have nothing to act on it, so it returns true or false and then the script continues.
I think you also have a problem with this $_POST['$k'] since it appears you should be just using $k
Try this:
if (is_array($_POST['Liked'])) {
foreach($_POST['Liked'] as $k)
{
$message .= '<span style="text-decoration:underline; font-weight:bold">Liked</span>: ' .
stripslashes($k);
}}
Michael J

Thank you, sir, that works out groovy. I'm back on the road again!
As I understand it, now the "if" part, when the page loads, is finding that it's not an array, so it doesn't execute the foreach. Then when the array is populated, it does run the foreach(?) and that's why there's no more warning message when the page loads?

True!
And if we look at our previous conversation, isset() can also be used.
This:
if (isset ($_POST['Liked'])) {
...means, if the array $_POST['Liked'] is set / defined.
--
foreach(?)
foreach($_POST['Liked'] as $k) means:
"Loop through every element in the array $_POST['Liked'], and put the value into variable $k."
---
Fubar

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |