Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can do it both way... here the key concept is having a unique field like id in the database for eg you have id,name,username and password field in database table so look at both the ways below</p> <p><strong>1. using hyperlink</strong></p> <pre><code>&lt;?php mysql_connect("fostname","username","password"); mysql_select_db("database_name"); $q = mysql_query("SELECT * FROM tbl_name"); if(mysql_num_rows($q)&gt;0) { echo"&lt;table&gt;"; echo "&lt;tr&gt;&lt;td&gt;name&lt;/td&gt;&lt;td&gt;action&lt;/td&gt;&lt;/tr&gt;"; while($name = mysql_fetch_assoc($q)) { ?&gt; &lt;tr&gt;&lt;td&gt;&lt;?php echo $name['name'];?&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="delete.php?id=&lt;?php echo $name['id'];?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;?php } echo "&lt;/table&gt;"; } ?&gt; </code></pre> <p>this is what you do in listing page.... now look at delete.php which needs to be on the path as defined in hyperlink</p> <p>delete.php</p> <pre><code>&lt;?php mysql_connect("fostname","username","password"); mysql_select_db("database_name"); $id = $_GET['id']; $q = mysql_query("delete from tbl_name where id = '$id'"); header("Location: list.php"); ?&gt; </code></pre> <p><strong>2. Using form</strong></p> <pre><code>&lt;?php mysql_connect("fostname","username","password"); mysql_select_db("database_name"); $q = mysql_query("SELECT * FROM tbl_name"); if(mysql_num_rows($q)&gt;0) { echo"&lt;table&gt;"; echo "&lt;tr&gt;&lt;td&gt;name&lt;/td&gt;&lt;td&gt;action&lt;/td&gt;&lt;/tr&gt;"; while($name = mysql_fetch_assoc($q)) { ?&gt; &lt;tr&gt;&lt;td&gt;&lt;?php echo $name['name'];?&gt;&lt;/td&gt;&lt;td&gt;&lt;form action='delete.php' method='post'&gt; &lt;input type='hidden' value='&lt;?php echo $name["id"];?&gt;'&gt;&lt;/form&gt;&lt;/td&gt;&lt;/tr&gt; &lt;?php } echo "&lt;/table&gt;"; } ?&gt; </code></pre> <p>delete.php</p> <pre><code>&lt;?php mysql_connect("fostname","username","password"); mysql_select_db("database_name"); $id = $_POSTs['id']; $q = mysql_query("delete from tbl_name where id = '$id'"); header("Location: list.php"); ?&gt; </code></pre> <p>(note: list.php is the page where you list all the info)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload