1

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'"

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Furkan
  • 141
  • 1
  • 13
  • change `$select='selected';` to `$select='checked';` – krishna Mar 03 '14 at 10:12
  • also you have not executed insert query. – krishna Mar 03 '14 at 10:12
  • 1
    what if you change `"where 'groupid'='$targetid'";` with `"where groupid='$targetid'";` – zzlalani Mar 03 '14 at 10:14
  • 2
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Mar 03 '14 at 10:20
  • groupid='$targetid'" is working – Furkan Mar 03 '14 at 12:47
  • you cant use normal quotes ('') for column name, that is used for variables like varchar. For column,table name you use other quotes -> backticks (``). – Bojan Kovacevic Mar 03 '14 at 12:53

0 Answers0