unlink/delete file from mysql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jessica87
    New Member
    • May 2008
    • 10

    unlink/delete file from mysql database

    hi there....
    i need some guidance here with
    this code?

    Code: ( text )

    1.
    $myFile = "testFile.t xt";
    2.
    $fh = fopen($myFile, 'w') or die("can't open file");
    3.
    fclose($fh);



    and this one too
    Code: ( text )

    1.
    $myFile = "testFile.t xt";
    2.
    unlink($myFile) ;




    and my question is...
    1) can i use this code to delete/unlink my file from mysql database?
    2)or can i use the common delete code to delete my file?
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Just run a DELETE query (or UPDATE query).

    Code:
    DELETE FROM `table` WHERE `id` = '".$_GET['id']."'
    
    UPDATE `table` SET `file` = '' WHERE `id` = '".$_GET['id']."'
    Use the one which fulfills your needs.
    Is it what you want?

    Comment

    • jessica87
      New Member
      • May 2008
      • 10

      #3
      erm....
      it's ok guys...
      i solved it again.....
      i use the common delete coding to delte the file from my database..
      this is the code i use ^_^

      [PHP]<?
      include("connec tdb.php");

      $id=$_GET['id'];
      mysql_query("de lete from filestorage where FileId='$id'");
      mysql_close();
      header("locatio n:list_filesZ.p hp");
      ?>[/PHP]

      Comment

      • jessica87
        New Member
        • May 2008
        • 10

        #4
        Originally posted by hsriat
        Just run the DELETE query (or UPDATE query).

        Code:
        DELETE FROM `table` WHERE `id` =  '".$_GET['id']."'
        
        UPDATE `table` SET `file` = '' WHERE `id` = '".$_GET['id']."'
        Use the one which fulfills your needs.
        Is it what you want?

        ya...just the same code i try myself...Thank u ^_^

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by jessica87
          ya...just the same code i try myself...Thank u ^_^
          You are welcome

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by jessica87
            erm....
            it's ok guys...
            i solved it again.....
            i use the common delete coding to delte the file from my database..
            this is the code i use ^_^

            [PHP]<?
            include("connec tdb.php");

            $id=$_GET['id'];
            mysql_query("de lete from filestorage where FileId='$id'");
            mysql_close();
            header("locatio n:list_filesZ.p hp");
            ?>[/PHP]
            You should, as good practice, uppercase your mysql reserved words (eg: WHERE, FROM, SELECT ... ) and also wrap column names, table names, etc in backticks.

            [php]
            $_mysql = "SELECT `col_1` FROM `tbl_1` WHERE `col_1` = 'safe'";
            [/php]

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by markusn00b
              You should, as good practice, uppercase your mysql reserved words (eg: WHERE, FROM, SELECT ... ) and also wrap column names, table names, etc in backticks.

              [php]
              $_mysql = "SELECT `col_1` FROM `tbl_1` WHERE `col_1` = 'safe'";
              [/php]
              Very good point... I'm also in favor of this.

              Although PHP, SQL and JavaScript are not too strict in syntax, but one should always follow a proper rule.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Also, need some mysql_real_esca pe_string()'ing going on up there.

                You're vulnerable to attacks!

                Comment

                • jessica87
                  New Member
                  • May 2008
                  • 10

                  #9
                  You should, as good practice, uppercase your mysql reserved words (eg: WHERE, FROM, SELECT ... ) and also wrap column names, table names, etc in backticks.
                  okay..^_^

                  i'll remember it...Thanks for the tip...
                  i do learn a lot from this forum....

                  Comment

                  Working...