Code not deleting the Respective rows from MYSQL table using PHP -
the following code displays table having 4 columns --> id : int; anytext : text; varcar : varchar, insertdate :timestamp
<?php $sql_r="select * 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 sql code deleting particular row
if(isset($_post['id_delete2'])) { $id_k=$_post['id_r']; { $query="delete abcd id='".$id_k."'"; if($query_run=mysql_query($query)) { header('location:exampl.php?suc=1'); } else { header('location:exampl.php?suc=0'); } }
please in finding mistake !
just change line of code
$id_k=$_post['id_r'];
with
$id_k=$_post['id_delete2'];
because field name id_delete2
<input type='hidden' name='id_delete2' value='".$id_r."'> ^^^^^^^^^^
Comments
Post a Comment