Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When i show this php on browser i couldn't get any value to table. My table is empty.

<?php 

    $sql = "select * from worksets where 'groupid'='$targetid'";
    $query = mysql_query($sql);

    $kadro=$_GET['kadro'];

    if((mysql_num_rows($query) > 0)) {
        while($result = mysql_fetch_array($query)) {
            $groupid =  $result[0];
            $groupname = $result[2];
            $sql2 = "select flag from havestatus where kadroid='$kadro' and yid='$groupid'";
            $query2 = mysql_query($sql2);

            if((mysql_num_rows($query2) == 0)) {
                $sql3 = "insert into havestatus values('$kadro','$yid',0)";
            } else {
                $select='selected';
            }
            ?>
            <tr>
                <td width='50%'><?php echo $groupname;?></td>
                <td></td>
                <td width='20%'><input type="checkbox" name="bev" checked="<?php echo $select; ?>"></td>
            </tr>
            <?php
        }
    }
?>

If i change code in simple way like;

It shows some values and unfunctional checkbox.

I need to get some values from database and fill checkboxs according to 0 or 1 from database and i have to insert all check box values with one form submit button to database as different rows for every check box

<?php 

    $sql = "select * from worksets where groupid='$targetid'";
    $query = mysql_query($sql);

    if((mysql_num_rows($query) > 0)) {
        while($result = mysql_fetch_array($query)) {
            $groupid =  $result[0];
            $groupname = $result[2];
            ?>

            <tr>
                <td width='50%'><?php echo $groupname;?></td>
                <td></td>
                <td width='20%'><input type="checkbox" name="bev"></td>    
            </tr>
            <?php
        }
    }
?>

it is work after 'groupid'='$targetid'" to groupid='$targetid'"

share|improve this question
    
change $select='selected'; to $select='checked'; –  krishna Mar 3 at 10:12
    
also you have not executed insert query. –  krishna Mar 3 at 10:12
1  
what if you change "where 'groupid'='$targetid'"; with "where groupid='$targetid'"; –  zzlalani Mar 3 at 10:14
2  
Danger: You are using an obsolete database API and should use a modern replacement. You are also vulnerable to SQL injection attacks that a modern API would make it easier to defend yourself from. –  Quentin Mar 3 at 10:20
    
groupid='$targetid'" is working –  Furkan Mar 3 at 12:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.