0

how to assign database values to checkboxes from the following code i am geting only one value through post

<form method="POST">
<?php
$j=0;
while ($value1 = mysql_fetch_row($value)) { ?>
    <table>
    <tr>
    <td>
    <input type='checkbox' name='expert'  value=' <?php echo $value1[1]; ?>' >
    <?php echo $value1[1]; ?> </td>
    <td>
    <input type='checkbox' name='intrest' value="<?php echo $value1[2]; ?>">
     <?php echo $value1[2]; ?></td>
    </tr>
   </table> 
}
?>
<input type="submit" name="submitForm" value="submit" />
</form>



<?php 
$Area=$_POST[expert];

echo "<p>".$Area."</p>";

?>

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by vaultdweller123
0

you are required do as below -

<td>
<input type='checkbox' name='expert' value='' <?php if($value1[1]!=''){ echo "checked";}; ?> >
<?php echo $value1[1]; ?> </td>
0

here is my algorithm to your problem, just changed the values.

<?php

if(isset($_POST['btnsubmit'])){
$chk = $_POST['chk'];
foreach($chk as $val){
echo $val."<br />";
}
}

?>

<form method='post'>
<?php
while($row=mysql_fetch_array($sql)){
echo "<input type='checkbox' name='chk[]' value='".$row['fields']."' /> ".$row['fields']."<br />";
?>
<input type='submit' name='btnsubmit' value='submit' />
</form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.