Any body who good with php OOP mysqli?

Hercules

New member
Not to waste you time here what im trying to do. I have a php page called delete.php which connects to a database, select content and loads each content $id, $name, $email $content on the same row in a HTML table.

When I click on one of many submit buttons being displayed, the form goes to another page process the delete sql and that page redirct back to delete.php with one less entry from th database being displayed

require_once("conn/connection.php");
$stmt = $conn->prepare('SELECT id, name, email, content FROM data');
$stmt->execute(); //excuteing statment
$stmt->bind_result($id, $name, $email, $content);

Above i use prepare statement and mysqli to select what i want.

<form method="post" action="deleteEntry.php">
<table>
<?php while($row = $stmt->fetch()) : ?>
<tr>
<td><?php echo $name;?></td>
<td><?php echo $email;?></td>
<td><?php echo $content;?></td>
<td><input type="submit" name="submit" id="<?php echo $id;?>" value="Delete" /></td>
</tr>
<?php endwhile;?>
</table>
</form>

Above I fetch the the content $id,$anme $email etc, and display it in a table row. which looks like

- - - Delete
- - - Delete
- - - Delete
- - - Delete
etc

<?php

require_once("conn/connection.php");

$id = $_POST['id'];

$stmt = $conn->prepare('DELETE FROM data WHERE id=? LIMIT 1');
$stmt->bind_param(i, $id);
$stmt->execute();
$stmt->close();
header("location: delete.php");

Above is my deleteEntry.php page code.
I thinks the id is somehow being destroyed when it goes to deleteEntry.php i think!
FIXED: it was trying to get the sumbit button to store the id for some reason what was i thinking. I never worked with the hidden field before maybe that was why

<input type="hidden" name="id" value="<?php echo $id; ?>" />
 
Back
Top