I’m a beginner in web development. I made a simple table that shows the id,answer and date of notes that I insert into the db.I need a simple script that shows a delete button for each note. I would like to know how can I get the id of each row I need to delete.
Here’s my php code:
<html>
<body>
<?php
include '..//config.php';
$result = mysql_query("SELECT * FROM **** Order by `id` ASC");
echo "<center><table width='400' border='1'>
<tr>
<th bgcolor='#D6D6D6' >ID</th>
<th bgcolor='#D6D6D6'>Answer</th>
<th bgcolor='#D6D6D6'>Date</th>
<th bgcolor='#D6D6D6'>Preview</th>
<th bgcolor='#D6D6D6'>Delete</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td bgcolor='#3399FF' scope='col width ='10%'>" . $row['id'] . "</td>";
echo "<td width ='10%'>" . $row['answer'] . "</td>";
echo "<td bgcolor='#3399FF' scope='col width ='10%'>" . $row['date'] . " </td>";
if ($row['hidden'] > 'http://www.********/upload/upload/') {
echo "<td width ='10%'><a href =" . $row['hidden'] . "><center>View</center></a></td>"; } else {echo "<td width ='10%'>" . $row[''] . "</td>";}
echo "<td width ='10%'><a href = 'dlt.php'>Delete</a></td>";
$row_id = $row['id'];
}
echo "</tr width ='10%'>";
echo "</table></center>";
?>
</body>
</html>
It’s not very clear from your question what your requirements are but I am assuming you want to know how you can pass the
idof the entry when you click the “Delete” link (which is linked todlt.php).You can pass a query string parameter to
dlt.phpwith theidof the entry.I have cleaned up your code and modified it below:
Then in your dlt.php file you can retrieve the
idto be deleted using the following line:Since you are new to web development (or development in general) you should be very careful about a couple of things:
mysql_*functions are deprecated. You should usemysqliorPDOinstead.I’d put in more points but the list can actually get very long. These should be good for starters.