doujupa7567 2016-07-08 12:48
浏览 22

PHP - 更新sql数据

i'm new to php and i have this php script, but for some reason its not working. What i want is when the checkbox is checked, the value of the specific table will increase by 1 after i click the 'submit' button.

php:

<?php
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['check_list'])){
foreach($_POST['check_list'] as $selected){
$sql = "UPDATE users SET marks = marks + 2 WHERE id = $selected";
mysqli_query($sql);
}
}
}
?>

and here is my table code which collect the data:

<form action="#" method="post">
    <table class='default'>
    <tr>
        <th>Delete</th><th>Username</th><th>Email</th><th>First Name</th><th>Last Name</th><th>Join Date</th><th>Last Sign In</th><th>Logins</th>
    </tr>
        <tbody>

<?php foreach ($userData as $v1) { ?>

            <tr>
            <td><input type="checkbox" name="check_list[]" value="<?=$v1->id?>" /></td>
            <td><?=$v1->username?></td>
            <td><?=$v1->fname?></td>
            <td><?=$v1->lname?></td>
            <td><?=$v1->marks?></td>
            <td><?=$v1->join_date?></td>
            </tr>
            <?php } ?>

        </tbody>
    </table>
    <input type="submit" name="submit" value="Submit"/>
</form>

where am i doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题