简体   繁体   中英

How to send data that is not in a textbox via post in PHP

I want to send the id no. in a form so that i can delete the specific row, how do I do it?

...
$query = "SELECT id, text1, file FROM dynamic";
$resultObj = $connection->query($query);
...
<?php while($row = $resultObj->fetch_assoc()): ?>
<p><?=$row['text1']?><br> 
<?php echo "<img src=".$row['file']." height=200 width=300 />"?>
</p><form action="server.php" method="post"> <button type="submit" name="delete_data">Delete</button></form>
<br>    <br>
<?php endWhile; ?>
...

The button should then delete the specific entry only

You can place all into one form. Names can have brackets generating an array. Buttons can have a value.

<button type='submit' name='delete_data[]' value='{$row['file']}'>Delete</button>

Consider doing this with checkboxes and one button 'Delete checked items'.

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