SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Why isn't this working?

    I have a code on a page, where I list a couple of movie clips.
    When I check a checkbox I can delete the movie in that specific folder, but the movie listed in mySql is still connected.
    So I need to remove the same movie from my table as well, not only from the folder. But I just can't make it work.

    Can anyone see what the problem might be in this little part?

    PHP Code:
    if(isset($_POST['MM_submit'])) {
    $imgdir=$row_rs_director['director_id'];
    foreach(
    $_POST['delete'] as $del) {
    $sql "DELETE FROM of_films WHERE video='$del'";
    $result mysql_query($sql) or die(mysql_error());
    unlink($imgdir.$del); # deletes the file 
    I've made this in Dreamweaver.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try echoing the query:
    PHP Code:
    $sql "DELETE FROM of_films WHERE video='$del'";
    echo 
    $sql.'<br />'
    ..and make sure it looks ok and that the video does exist in the database. Also try running the query manually if you have phpMyAdmin (for example) or from a mysql command prompt.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by brad62
    I have a code on a page, where I list a couple of movie clips.
    When I check a checkbox I can delete the movie in that specific folder, but the movie listed in mySql is still connected.
    So I need to remove the same movie from my table as well, not only from the folder. But I just can't make it work.

    Can anyone see what the problem might be in this little part?

    PHP Code:
    if(isset($_POST['MM_submit'])) {
    $imgdir=$row_rs_director['director_id'];
    foreach(
    $_POST['delete'] as $del) {
    $sql "DELETE FROM of_films WHERE video='$del'";
    $result mysql_query($sql) or die(mysql_error());
    unlink($imgdir.$del); # deletes the file 
    I've made this in Dreamweaver.

    1.kindly check the presence of connection parameter.... assuming you're using mysql_connect etc...
    2.was your filename ($del) is actually the content of video field?
    3.can you do var_dump("<pre>",$result) and post the result here?

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mark. Now I know what's wrong at least.

    It echoed :
    PHP Code:
    video='/test.mov' 
    So I need to get rid of the slash there in front.
    Since I'm usually confused and never learn this.
    How do I do this? I did it before, but as soon as look at a code like this I keep forgetting what I did.
    I guess I should do php more often, so I might learn it one day.

  5. #5
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can either do:
    $sql = "DELETE FROM of_films WHERE video='".basename($del)."'";

    or:
    $sql = "DELETE FROM of_films WHERE video='".trim($del, '/')."'";

    As you're dealing with paths and filenames I'd use the first (basename) one.

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What would I do without this Forum?
    This was great. It's working. Thanks a lot.
    Never read anything about that solution with .basename
    Nice to learn something new.

    So that part is actually making it moving up in the directory by removing a slash or what?
    The trim part I knew about, but didn't think about that for this really. I was more into something like finding the first LEFT letter. But this was probably better, since it's working.


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
  •