The following code displays a table having 4 columns --> id : INT; anytext : TEXT; varcar : VARCHAR, insertdate :TIMESTAMP
<?php
$sql_r="SELECT * FROM abcd ";
if($records_r=mysql_query($sql_r))
{
echo ' ';
$k_r=1;
while($ven_r=@mysql_fetch_assoc($records_r))
{
$id_r=$ven_r['id'];
$anytext_r=$ven_r['anytext'];
$varcar_r=$ven_r['varcar'];
$insertdate_r=$ven_r['insertdate'];
echo"<tr>";
echo "<td>
<form method='POST' action='example.php'>
<input type='hidden' name='id_delete2' value='".$id_r."'>
<button type='submit' class='btn btn-primary'>".$k_r."</button>
</form><td>";
echo "<td>".$anytext_r."</td>";
echo "<td>".$varcar_r."</td>";
echo "<td>".$insertdate_r."</td>";
echo"</tr>";
$k_r+=1;
}
}
?>
This is the SQL code for deleting a particular row
if(isset($_POST['id_delete2']))
{
$id_k=$_POST['id_r'];
{
$query="DELETE FROM abcd WHERE id='".$id_k."'";
if($query_run=mysql_query($query))
{
header('Location:exampl.php?suc=1');
}
else
{
header('Location:exampl.php?suc=0');
}
}
Please help in finding where is mistake !
Just change this line of code
With
Because your field name is
id_delete2