473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

unlink/delete file from mysql database

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
8 3874
hsriat
1,654 Expert 1GB
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
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
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
1,654 Expert 1GB
ya...just the same code i try myself...Thank u ^_^
You are welcome

May 25 '08 #5
Markus
6,050 Expert 4TB
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
1,654 Expert 1GB
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
6,050 Expert 4TB
Also, need some mysql_real_escape_string()'ing going on up there.

You're vulnerable to attacks!
May 25 '08 #8
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

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

Similar topics

2
by: Eric | last post by:
Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a MySql database. The upoaded file itself is stored...
7
by: 3A Web Hosting | last post by:
Hi Folks I'm trying to delete a file. unlink('../images/photos/1967_GT_500_Shelby_Mustang.jpg'); That works $fm = "../images/photos/1967_GT_500_Shelby_Mustang.jpg"; unlink($fm); That...
5
by: Phil Powell | last post by:
print_r(is_file("$logPath/$logFileName")); // RETURNS 1 unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED This code should tell me that the file located at...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
10
by: lorenzogordon | last post by:
Hi there, I'd greatly appreciate any insights into the following problem: I've got PHP running fine on IIS (OS: Server 2003, SP1; IIS: 6.0; PHP: 4.3.11). In PHP, the user uploads a file,...
6
by: Benjamin | last post by:
Hello, I'm running PHP 5.2.0 as a Apache 2.2 server module. When, I try to unlink I get this: "Warning: unlink(file.txt) : Permission denied..." What and how do I change this so it works? Thanks
4
by: nitinpatel1117 | last post by:
Hi I am trying to delete a csv file using the unlink() function, but i keep getting a permission denied warning Warning: unlink(UsedNOS200704191.CSV): Permission denied in...
15
by: Morteneistrom | last post by:
Im a complete n00b at PHP so please forgive me if this i a stupid question Why wont the following work. PHP Code: <?php foreach (glob('../images/profil/*.jpg') as $filename) { echo...
11
by: byteoart | last post by:
I'm a newbie to php. I am trying to delete a file from the server that I put there (one file, not the whole directory). I am using unlink ($filename); I did the path as a relative path as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.