Database Articles

  Home arrow Database Articles arrow Page 13 - Create dynamic sites with PHP & MySQL
DATABASE ARTICLES

Create dynamic sites with PHP & MySQL
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 54
    2002-05-19

    Table of Contents:
  • Create dynamic sites with PHP & MySQL
  • Introduction and installation
  • Installing Apache server routines
  • Installing MySQL
  • Installing PHP
  • Your first script
  • Your first database
  • Where's my view?
  • Creating an HTML form
  • Putting it together
  • Passing variables
  • Viewing individual rows
  • Deleting rows
  • Editing data
  • Searching our data
  • Tips for common tasks

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Create dynamic sites with PHP & MySQL - Deleting rows


    (Page 13 of 16 )

    So far we have only entered new information in our database and viewed it. Where's the fun if we can't trash some of those data, at least the useless ones? Our delete.php will do just that. It works exactly like view.php. The only difference is the SQL command "DELETE FROM personnel WHERE id=$id", which tell MySQL to delete the row that contains the id corresponding to the variable $id. Generally, the SQL command for deleting a row is DELETE FROM database_name WHERE field_name=somevalue

    <HTML> 
    <?php 
    $db = mysql_connect("localhost", "root", ""); 
    mysql_select_db("learndb",$db); 
    mysql_query("DELETE FROM personnel WHERE id=$id",$db); 
    echo "Information Deleted"; 
    ?> 
    </HTML>

    Once again we modify our previous viewdb2.php script to viewdb3.php to add this new feature. The additions should be obvious.

    <HTML> 
    <?php 
    $db = mysql_connect("localhost", "root", ""); 
    mysql_select_db("learndb",$db); 
    $result = mysql_query("SELECT * FROM personnel",$db); 
    echo "<TABLE BORDER=2>"; 
    echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
    while ($myrow = mysql_fetch_array($result)) 

    echo "<TR><TD>".$myrow["firstname"]." ".$myrow["nick"]; 
    echo "<TD><a href=\"view.php?id=".$myrow[id]."\">View</a> "; 
    echo "<a href=\"delete.php?id=".$myrow[id]."\">Delete</a>"; 

    echo "</TABLE>"; 
    ?> 
    </HTML>

    Try clicking on delete and then view the database again with viewdb3.php to verify that the row was really deleted. You may have to refresh your browser.

    More Database Articles Articles
    More By Codewalkers

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap