简体   繁体   中英

php while loop submit button

<?php
    $sel22 = mysql_query("SELECT id1nev, id2nev, id2, accept FROM barat WHERE id1= '$kariidje' AND accept = '1' ") or die("CANNOT FETCH DATA FOR ADMIN " . mysql_error());
    if (mysql_num_rows($sel22) > 0) {
        $i=0;
        while ($data22 = mysql_fetch_array($sel22)) {
            $i++;
          ?><tr>
                <td>
                    <?php
                        include 'elemek/connection.php'; 
                        $idkitfogadel = $data22['id2'];
                        if(isset($_POST["submitelutasit"])){
                            $updatebaratt1 = "DELETE FROM barat WHERE id1 = $kariidje and id2 = $idkitfogadel";
                            mysql_query($updatebaratt1);
                        //header("Location: friends.php");  
                        }

                    ?>

                    <form id="form<?php echo $i; ?>" method="POST" action="#">
                        <Button type="SUBMIT" name="submitelutasit" id="submitelutasit<?php echo $i;?>" value="!"/></button>
                    </form>
                </td>
                <td align="center">
                    <a>Something</a>
                </td>

            </tr>
<?php
}

This is my code in my page. The problem is if I press the button in any line its delete all my data and not only what i want. Each line each button when I press a button its delete that line where is it. This is what i want. I cant solve this problem (sad).

Thank you

I will just assume that you are just playing around, and that's not even near to the production code.

Add input field to your form with id2 so you can use it later.

<form id="form<?php echo $i; ?>" method="POST" action="#">
    <input type="hidden" name="id2" value="<?php echo $data22['id2'] ?>">
    <Button type="SUBMIT" name="submitelutasit" id="submitelutasit<?php echo $i;?>" value="!"/></button>
</form>

And use it like this:

$idkitfogadel = $_POST['id2'];

Inside your if(isset($_POST["submitelutasit"])) statement.

I'm sure that little kitty died somewhere right now :(

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