简体   繁体   中英

My php table changed the false row in my db

I'm a PHP beginner & have a question xd Whenever I click on the submit button, the data of the last user in the PHP table are changed.

Could somebody check on it?

 <?php
foreach ($db->results() as $unpaid){

    ?>
    <form method="POST">
        <tr><td>
            <?=$unpaid->id?>
            <input type="hidden" name="user" value="<?=$unpaid->id?>">
            </td>
            <td><?=$unpaid->username?>
            </td>
            <td><?=$unpaid->bitcoinadress?></td>
            <td><?=$unpaid->points?></td>
            <td><?=$unpaid->requestdate?></td>
            <td><?=$unpaid->status?></td>
            <td>

            <input type="submit" class="btn btn-warning" name="submit" value="Submit" /><br/>

            </td>


            </tr>


<?php } ?>

<?php
if(isset($_POST['submit']))  
$id = $POST_['user'];
$db->update("payment_request", $id, ["status"=>"Paid"]);

?>

</form>
</table>

You can't put a <form> around a <tr> . You need to put the form inside one of the <td> tags.

<table>
<?php
foreach ($db->results() as $unpaid){
    ?>
    <tr>
        <td> <?=$unpaid->id?> </td>
        <td><?=$unpaid->username?> </td>
        <td><?=$unpaid->bitcoinadress?></td>
        <td><?=$unpaid->points?></td>
        <td><?=$unpaid->requestdate?></td>
        <td><?=$unpaid->status?></td>
        <td>
        <form method="POST">
            <input type="hidden" name="user" value="<?=$unpaid->id?>">
            <input type="submit" class="btn btn-warning" name="submit" value="Submit" /><br/>
        </form>
        </td>
    </tr>
    <?php } ?>

<?php
if(isset($_POST['submit']))  
    $id = $POST_['user'];
$db->update("payment_request", $id, ["status"=>"Paid"]);

?>
</table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM