By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,515 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

unlink/delete file from mysql database

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

Code: ( text )

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



and this one too
Code: ( text )

1.
$myFile = "testFile.txt";
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?
May 25 '08 #1
Share this Question
Share on Google+
8 Replies


hsriat
Expert 100+
P: 1,654
Just run a DELETE query (or UPDATE query).

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM `table` WHERE `id` = '".$_GET['id']."'
  2.  
  3. UPDATE `table` SET `file` = '' WHERE `id` = '".$_GET['id']."'
Use the one which fulfills your needs.
Is it what you want?
May 25 '08 #2

P: 10
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("connectdb.php");

$id=$_GET['id'];
mysql_query("delete from filestorage where FileId='$id'");
mysql_close();
header("location:list_filesZ.php");
?>[/PHP]
May 25 '08 #3

P: 10
Just run the DELETE query (or UPDATE query).

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM `table` WHERE `id` =  '".$_GET['id']."'
  2.  
  3. 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 ^_^
May 25 '08 #4

hsriat
Expert 100+
P: 1,654
ya...just the same code i try myself...Thank u ^_^
You are welcome

May 25 '08 #5

Markus
Expert 5K+
P: 6,050
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("connectdb.php");

$id=$_GET['id'];
mysql_query("delete from filestorage where FileId='$id'");
mysql_close();
header("location:list_filesZ.php");
?>[/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]
May 25 '08 #6

hsriat
Expert 100+
P: 1,654
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.
May 25 '08 #7

Markus
Expert 5K+
P: 6,050
Also, need some mysql_real_escape_string()'ing going on up there.

You're vulnerable to attacks!
May 25 '08 #8

P: 10
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....
May 25 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.