Results 1 to 3 of 3

Thread: PHP/MySQL - Delete from two tables and server files

  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP/MySQL - Delete from two tables and server files

    Currently, my site is set up so you have to delete all the music and then the band if you want both gone. I'd like to make it so that if a band is deleted, all their music is as well. I am using Dreamweaver CS3

    To delete the music only I have an unlink:

    PHP Code:
    if ((isset($_POST['musicID'])) && ($_POST['musicID'] != "")) {
      
    $image_path '../includes/audio/';
        if (isset(
    $_POST['trackdirectory']) && file_exists($image_path.$_POST['trackdirectory'])) {
          
    unlink($image_path.$_POST['trackdirectory']);
          }
      
      
    $deleteSQL sprintf("DELETE FROM music WHERE musicID=%s",
                           
    GetSQLValueString($_POST['musicID'], "int"));
                       
      
    mysql_select_db($database_everyscene$everyscene);
      
    $Result1 mysql_query($deleteSQL$everyscene) or die(mysql_error());

      
    $deleteGoTo "viewbands.php";
      if (isset(
    $_SERVER['QUERY_STRING'])) {
        
    $deleteGoTo .= (strpos($deleteGoTo'?')) ? "&" "?";
        
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      
    header(sprintf("Location: %s"$deleteGoTo));

    My delete artist page currently is:

    PHP Code:
    if ((isset($_POST['artistID'])) && ($_POST['artistID'] != "")) {
      
    $deleteSQL sprintf("DELETE FROM artists WHERE artistID=%s",
                           
    GetSQLValueString($_POST['artistID'], "int"));

      
    mysql_select_db($database_everyscene$everyscene);
      
    $Result1 mysql_query($deleteSQL$everyscene) or die(mysql_error());

      
    $deleteGoTo "viewbands.php";
      if (isset(
    $_SERVER['QUERY_STRING'])) {
        
    $deleteGoTo .= (strpos($deleteGoTo'?')) ? "&" "?";
        
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      
    header(sprintf("Location: %s"$deleteGoTo));


    Is there a way to add the delete music from a band into the delete a band page? My music table is currently set up as: musicID, track_directory (which links to the server file), artistID (which links to the artist table). Thank you

  2. #2
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Does any of that make sense?

  3. #3
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Unless I am misunderstanding you have posted here is a simple way to delete all the artists music if the artist is deleted.

    PHP Code:
    if ((isset($_POST['artistID'])) && ($_POST['artistID'] != "")) { 

    $artist=$POST['artistID']; 
     
    $delartist "DELETE FROM artists WHERE artistID=$artist";
    $delmusic "DELETE FROM music WHERE artistID=$artist";

    $Result1 mysql_query($delartist) or die(mysql_error()); 
    $Result2 mysql_query($delmusic) or die(mysql_error()); 
    You obviously need to open your database before this code, I haven't tested it but it should work.

    There are other ways of doing this, by joining the tables, but that is a bit more complicated.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •