PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1845
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
can someone help me Posted by epolmuse on 12 Apr 2008 at 1:05 AM
<?
include("../db.php");
?><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../forAll.css" rel="stylesheet" type="text/css">

</head>

<body>
<?
include("upload_courses.php");


if($_GET[pro]=="del"){
$sql = "DELETE FROM tbl_upload WHERE id_upload='$_GET[id_upload]'";
$result = mysql_query($sql);

chdir('http://localhost/epol/admin/upload');
$do = unlink($_GET[file_name]);
if($do=="1"){
echo "The file was deleted successfully.";
} else
{ echo "There was an error trying to delete the file."; }

header("location:module.php?module=upload&op=upload_courses&id_courses=$_GET[id_courses]");
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="forMenu"><div align="center">Category Of Upload</div><br></td>
</tr>
<?
$bil=0;
$sql = "SELECT * FROM tbl_courses";
$result = mysql_query($sql);

while($rows = mysql_fetch_array($result))
{
if($bil%5==0)
{
print("<tr>");
}
$bil++;
?>
<td class="forTexts"><a href="module.php?module=upload&op=upload_courses&id_courses=<? echo $rows['id_courses'];?>"><? echo $rows['courses'];?></a>(
<?
$id_courses = $rows['id_courses'];
$count = "SELECT COUNT(id_courses) FROM tbl_upload WHERE id_courses='".$id_courses."'";
$exec = mysql_query($count);

while($row = mysql_fetch_array($exec)){
echo $row['COUNT(id_courses)'];
}

?>
)</td>
<?
if($bil==5)
{
print("</tr>");
$bil=0;
}

}
?>
</table><br><br>
<?
if($_GET[id_courses]==NULL){
echo NULL;
}else{
?>
<table width="100%" border="0" cellpadding="0" cellspacing="2" class="forTexts">
<tr>
<td width="2%" bgcolor="#c1cede"><strong>No</strong></td>
<td width="80%" bgcolor="#c1cede"><strong>File Name</strong></td>
<td width="18%" bgcolor="#c1cede"><strong>Action</strong></td>
</tr>
<?
$num = 1;
$sql = "SELECT * FROM tbl_upload WHERE id_courses='".$_GET[id_courses]."'";
$result = mysql_query($sql);

while($rows = mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#58a9fb"><? echo $num++; ?></td>
<td bgcolor="#58a9fb"><? echo $rows['$file_name']; ?></td>
<td bgcolor="#58a9fb"><a onCLick="return confirm('Are you SURE you want to delete this record?')" href="module.php?module=upload&op=upload_courses&pro=del&id_courses=<? echo $_GET[id_courses]; ?>&id_upload=<? echo $rows['id_upload']; ?>">Delete</a></td>
</tr>
<? } ?>
</table>
<? } ?>
</body>
</html>

can someone help me, right now im trying to delete the file that has been uploaded...when i delete right now the in the database the file has been deleted but in the upload folder, the file still hasn't been deleted...can anyone help me?
Report
Re: can someone help me Posted by tvienti on 23 Apr 2008 at 2:02 PM
: <?
: include("../db.php");
: ?><html>
: <head>
: <title>Untitled Document</title>
: <meta http-equiv="Content-Type" content="text/html;
: charset=iso-8859-1">
: <link href="../forAll.css" rel="stylesheet" type="text/css">
:
: </head>
:
: <body>
: <?
: include("upload_courses.php");
:
:
: if($_GET[pro]=="del"){
: $sql = "DELETE FROM tbl_upload WHERE id_upload='$_GET[id_upload]'";
: $result = mysql_query($sql);
:
: chdir('http://localhost/epol/admin/upload');
: $do = unlink($_GET[file_name]);
: if($do=="1"){
: echo "The file was deleted successfully.";
: } else
: { echo "There was an error trying to delete the file."; }
:
: header("location:module.php?module=upload&op=upload_courses&id_cour
: ses=$_GET[id_courses]");
: }
: ?>
: <table width="100%" border="0" cellspacing="0" cellpadding="0">
: <tr>
: <td class="forMenu"><div align="center">Category Of
: Upload</div><br></td>
: </tr>
: <?
: $bil=0;
: $sql = "SELECT * FROM tbl_courses";
: $result = mysql_query($sql);
:
: while($rows = mysql_fetch_array($result))
: {
: if($bil%5==0)
: {
: print("<tr>");
: }
: $bil++;
: ?>
: <td class="forTexts"><a
: href="module.php?module=upload&op=upload_courses&id_courses=<? echo
: $rows['id_courses'];?>"><? echo $rows['courses'];?></a>(
: <?
: $id_courses = $rows['id_courses'];
: $count = "SELECT COUNT(id_courses) FROM tbl_upload WHERE
: id_courses='".$id_courses."'";
: $exec = mysql_query($count);
:
: while($row = mysql_fetch_array($exec)){
: echo $row['COUNT(id_courses)'];
: }
:
: ?>
: )</td>
: <?
: if($bil==5)
: {
: print("</tr>");
: $bil=0;
: }
:
: }
: ?>
: </table><br><br>
: <?
: if($_GET[id_courses]==NULL){
: echo NULL;
: }else{
: ?>
: <table width="100%" border="0" cellpadding="0" cellspacing="2"
: class="forTexts">
: <tr>
: <td width="2%" bgcolor="#c1cede"><strong>No</strong></td>
: <td width="80%" bgcolor="#c1cede"><strong>File Name</strong></td>
: <td width="18%" bgcolor="#c1cede"><strong>Action</strong></td>
: </tr>
: <?
: $num = 1;
: $sql = "SELECT * FROM tbl_upload WHERE
: id_courses='".$_GET[id_courses]."'";
: $result = mysql_query($sql);
:
: while($rows = mysql_fetch_array($result)){
: ?>
: <tr>
: <td bgcolor="#58a9fb"><? echo $num++; ?></td>
: <td bgcolor="#58a9fb"><? echo $rows['$file_name']; ?></td>
: <td bgcolor="#58a9fb"><a onCLick="return confirm('Are you SURE
: you want to delete this record?')"
: href="module.php?module=upload&op=upload_courses&pro=del&id_courses=<
: ? echo $_GET[id_courses]; ?>&id_upload=<? echo $rows['id_upload'];
: ?>">Delete</a></td>
: </tr>
: <? } ?>
: </table>
: <? } ?>
: </body>
: </html>
:
: can someone help me, right now im trying to delete the file that has
: been uploaded...when i delete right now the in the database the file
: has been deleted but in the upload folder, the file still hasn't
: been deleted...can anyone help me?

Can you give us more information? Your code seems to include error checks that tell you if the file was deleted or not... what's it saying? Your error checking is looking for "1" to be returned from unlink in a success case, but unlink returns true or false. Not sure how PHP will compare "1" and true, but you should always use typed comparisons when possible, and this is a good place to do it. For example:

$do = unlink('/path/to/file');
if ($do === TRUE)
    echo 'Success! :D';
else
    echo 'Failure :(';



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.