Hi i have got multiple check box working in test file but when i try and put it and check box all i get is array i put this bit in profile.php

$length = count($interests);

for ($i = 0; $i < $length; $i++){
    echo $interests[$i];
    echo '    ';
}
?>

in the html bit but wrapped php round it

and this bit in php block on edit profile and i get the following

$interests = $_POST['interests'];



Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jktempla/public_html/cedit_profile.php on line 57

and if i keep the existing

interests       = '".$_POST['interests']."' ,

i get the following : ARRAY where the selections are to show

can anyone tell me where to put all any help would be much appriecated x

this is the complete check box code

<?php
$interests = $_POST['interests'];

$length = count($interests);

for ($i = 0; $i < $length; $i++){
    echo $interests[$i];
    echo '    ';
}
?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" /> <meta name="author" content="Kevin Robinson" /> <title>Untitled 2</title> </head> <body> <form method="post"> <table width="900"> <tbody> <tr> <td width="900"><input name="interests[]" id="option1" value="option1" type="checkbox"><p style="font-size:+1;">option1</p></td> <td width="900"><input name="interests[]" id="option2" value="option2" type="checkbox">option2</td> <td width="900"><input name="interests[]" id="option3" value="option3" type="checkbox">option3</td> </tr> </tbody> </table> <input type="submit" value="Show my Items" name="save"/> </body> </html> 

Something like this should be working:

<?php
$interests = array();

if (!empty($_POST['interests'])) {
    $interests = $_POST['interests'];
}

if ($interests) {
    echo 'Interests:<br>';
    foreach ($interests as $i => $interest) {
        echo 'Interest: ' . $interest . '<br>';
    }
} else {
    echo 'No interests submitted.<br>';
}

?> 
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html"><meta name="author" content="Kevin Robinson"><title>Untitled 2</title> </head> <body> <form method="post"> <table width="900"> <tbody> <tr> <td width="900"><input name="interests[]" id="option1" value="option1" type="checkbox"><p style="font-size:+1;">option1</p></td> <td width="900"><input name="interests[]" id="option2" value="option2" type="checkbox">option2</td> <td width="900"><input name="interests[]" id="option3" value="option3" type="checkbox">option3</td> </tr> </tbody> </table> <input type="submit" value="Show my Items" name="save"></body> </html> 

Your code shouldn't be giving any errors for as far as I can see. Only thing that could happen is that a notice is triggered because you aren't checking if $_POST['interests'] actually contains a value before using it.

hi hun ive put it through and when i check boxes i get the following :

No interests submitted.

ive checked by name in database and each check box name etc and there is no change x

I ran the same code locally and it's working (the code I submitted as an example, that is). So if that's not working for you we may have bigger problems at work here :p.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.