Jump to content

unlink()


dsjoes

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

unexpected end might be because you put the close bracket within the html instead of the php

 

<?php
while($row=mysql_fetch_array($result1)){
?>

table part here
<?php
} // end while
?>

 

sorry posted old bit and i still get the same message with the php tag

 

if i remove the { } parts i get the message below

<?php while($row = mysql_fetch_array($result1))  ?>

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 48

 

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157189
Share on other sites

i have added the error bit

<?php while($row = mysql_fetch_array($sql) or die("Query Failed: $sql " . mysql_error()))  ?>

 

i now get this

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 48

Query Failed: select * from `docs` order by `id`;

 

 

<?php
// Set Global Vars
$HOST = "XXXXX";
$USERNAME = "XXXXX";
$PASSWORD = "XXXXX";
$DATABASE = "testdocs";
$TABLE = "docs";
// Establish a connection
mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());
// Query for results
if(!isset($_POST['delete'])) {
$sql = "select * from `$TABLE` order by `id`;";
} else {
$DELETE_ID = mysql_real_escape_string($_POST['delete']);
$result1 = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';");
$row = mysql_fetch_assoc($result1);
mysql_close($result1);
// Delete the file on the disk
unlink('../admin/docs/'.$row['Download']);
// Build your query, kind of weird but alright.
$sql = ("delete from $TABLE where ");
for($i=0;$i<count($_POST['checkbox']);$i++){
if($i != 0) { $sql.= "AND "; }
$sql .= " id='" . $_POST['checkbox'][$i] . "'";
}
$result = mysql_query($sql);
if(isset($_POST['delete'])) { 
header('Location: index.php');
exit;
}
}
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="400" border="1" cellpadding="3" cellspacing="1">
<tr>
<td colspan="6" align="center"><strong>Testimonials</strong> </td>
</tr>
<tr>
<td align="center"><strong>Select</strong></td>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Description</strong></td>
<td align="center"><strong>Download</strong></td>
<td align="center"><strong>Last Modified</strong></td>
</tr><?php while($row = mysql_fetch_array($sql) or die("Query Failed: $sql " . mysql_error()))  ?>
        <tr>
                <td align="center">
                        <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">
                </td>
                <td align="center"><?php echo $row['id']; ?></td>
                <td align="center"><?php echo $row['Name']; ?></td>
                <td align="center"><?php echo $row['Message']; ?></td>
                <td align="center"><a href="/admin/docs/<?php echo $row['Download']; ?>">Download</a></td>
                <td align="center"><?php echo $row['Modified']; ?></td>
        </tr>
        <tr>
        <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
        </tr>
</table>
</form>
</td>
</tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157193
Share on other sites

<?php
// Set Global Vars
$HOST = "XXXXX";
$USERNAME = "XXXXX";
$PASSWORD = "XXXXX";
$DATABASE = "testdocs";
$TABLE = "docs";
// Establish a connection
mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());
// Query for results
if(!isset($_POST['delete'])) {
$sql = "select * from `$TABLE` order by `id`;";
} else {
$DELETE_ID = mysql_real_escape_string($_POST['delete']);
$result1 = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';");
$row = mysql_fetch_assoc($result1);
mysql_close($result1);
// Delete the file on the disk
unlink('../admin/docs/'.$row['Download']);
// Build your query, kind of weird but alright.
$sql = ("delete from $TABLE where ");
for($i=0;$i<count($_POST['checkbox']);$i++){
if($i != 0) { $sql.= "AND "; }
$sql .= " id='" . $_POST['checkbox'][$i] . "'";
}
$result = mysql_query($sql);
if(isset($_POST['delete'])) { 
header('Location: index.php');
exit;
}
}
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="400" border="1" cellpadding="3" cellspacing="1">
<tr>
<td colspan="6" align="center"><strong>Testimonials</strong> </td>
</tr>
<tr>
<td align="center"><strong>Select</strong></td>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Description</strong></td>
<td align="center"><strong>Download</strong></td>
<td align="center"><strong>Last Modified</strong></td>
</tr><?php while($row = mysql_fetch_array($sql))  ?>
        <tr>
                <td align="center">
                        <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">
                </td>
                <td align="center"><?php echo $row['id']; ?></td>
                <td align="center"><?php echo $row['Name']; ?></td>
                <td align="center"><?php echo $row['Message']; ?></td>
                <td align="center"><a href="/admin/docs/<?php echo $row['Download']; ?>">Download</a></td>
                <td align="center"><?php echo $row['Modified']; ?></td>
        </tr>
        <tr>
        <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
        </tr>
</table>
</form>
</td>
</tr>
</table>

 

it is still this line for the message

</tr><?php while($row = mysql_fetch_array($sql))  ?>

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157611
Share on other sites

$sql is not a valid MySQL result. where is $sql defined?

 

use $result. The code I posted earlier sets your query to $result, not $result1 or $sql.

 

</tr><?php while($row = mysql_fetch_array($result))  ?>

 

And if you haven't solved your error earlier, use a do while loop. Example:

 

<?php do { ?>

// Table code here

<?php } while($row = mysql_fetch_assoc($result1)); ?>

 

If you do the above you also need to set $row. Put the variable declaration before your loop.

 

 $row = mysql_fetch_assoc($result); 

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1158081
Share on other sites

is this correct because i still get the message

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 48

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 67

<?php
// Set Global Vars
$HOST = "XXXXXXXX";
$USERNAME = "XXXXXXXXXXXX";
$PASSWORD = "XXXXXXXX";
$DATABASE = "testdocs";
$TABLE = "docs";
// Establish a connection
mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());
// Query for results
if(!isset($_POST['delete'])) {
$sql = "select * from `$TABLE` order by `id`;";
} else {
$DELETE_ID = mysql_real_escape_string($_POST['delete']);
$result1 = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';");
$row = mysql_fetch_assoc($result1);
mysql_close($result1);
// Delete the file on the disk
unlink('../admin/testimonial_files/'.$row['Download']);
// Build your query, kind of weird but alright.
$sql = ("delete from $TABLE where ");
for($i=0;$i<count($_POST['checkbox']);$i++){
if($i != 0) { $sql.= "AND "; }
$sql .= " id='" . $_POST['checkbox'][$i] . "'";
}
$result = mysql_query($sql);
if(isset($_POST['delete'])) { 
header('Location: index.php');
exit;
}
}
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="400" border="1" cellpadding="3" cellspacing="1">
<tr>
<td colspan="6" align="center"><strong>Testimonials</strong> </td>
</tr>
<tr>
<td align="center"><strong>Select</strong></td>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Description</strong></td>
<td align="center"><strong>Download</strong></td>
<td align="center"><strong>Last Modified</strong></td>
</tr><?php $row = mysql_fetch_assoc($result); ?><?php do { ?>
        <tr>
                <td align="center">
                        <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">
                </td>
                <td align="center"><?php echo $row['id']; ?></td>
                <td align="center"><?php echo $row['Name']; ?></td>
                <td align="center"><?php echo $row['Message']; ?></td>
                <td align="center"><a href="/admin/docs/<?php echo $row['Download']; ?>">Download</a></td>
                <td align="center"><?php echo $row['Modified']; ?></td>
        </tr>
        <tr>
        <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
        </tr>
</table>
</form>
</td>
</tr>
</table>
<?php } while($row = mysql_fetch_assoc($result1)); ?>

 

these are the lines

<?php $row = mysql_fetch_assoc($result); ?><?php do { ?>

<?php } while($row = mysql_fetch_assoc($result1)); ?>

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1158101
Share on other sites

it now shows all of the records but the unlink still doesn't work and i now get a header message

 

here is the code

<?php
// Set Global Vars
$HOST = "XXXXXXX";
$USERNAME = "XXXX";
$PASSWORD = "XXXXX";
$DATABASE = "XXXXX";
$TABLE = "testdocs";
// Establish a connection
mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());

if (isset($_POST['delete'])) {
    // delete sql here
    $DELETE_ID = mysql_real_escape_string($_POST['delete']);
    unlink('../admin/testimonial_files/' . $row['Download']);
    $sql = ("delete from $TABLE where ");
    for ($i = 0; $i < count($_POST['checkbox']); $i++) {
        if ($i != 0) {
            $sql.= "AND ";
        }
        $sql .= " id='" . $_POST['checkbox'][$i] . "'";
    }
    $result = mysql_query($sql);
   header('Location: index.php');
   exit;
} else {
    // select sql here
    $sql = "select * from `$TABLE` order by `id`;";
    $result = mysql_query($sql);
}
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
        <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
                <table width="400" border="1" cellpadding="3" cellspacing="1">
                    <tr>
                        <td colspan="6" align="center"><strong>Testimonials</strong> </td>
                    </tr>
                    <tr>
                        <td align="center"><strong>Select</strong></td>
                        <td align="center"><strong>ID</strong></td>
                        <td align="center"><strong>Name</strong></td>
                        <td align="center"><strong>Description</strong></td>
                        <td align="center"><strong>Download</strong></td>
                        <td align="center"><strong>Last Modified</strong></td>
                    </tr><?php $row = mysql_fetch_assoc($result); ?><?php do { ?>
                        <tr>
                            <td align="center">
                                <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">
                            </td>
                            <td align="center"><?php echo $row['id']; ?></td>
                            <td align="center"><?php echo $row['Name']; ?></td>
                            <td align="center"><?php echo $row['Message']; ?></td>
                            <td align="center"><a href="/admin/testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>
                            <td align="center"><?php echo $row['Modified']; ?></td>
                        </tr>
                        <tr>
                            <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
                        </tr><?php } while ($row = mysql_fetch_assoc($result)); ?>
                    </table>
                </form>
            </td>
        </tr>
    </table>

 

these are the errors

Warning: unlink(/testimonial_files/) [function.unlink]: Is a directory in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 15

 

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php:15) in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 24

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1160370
Share on other sites

Are you getting any other warnings? I ask because I note that you're trying to use a variable that is defined as a result of the database query ($row['Downlload']) before you execute the query.

if (isset($_POST['delete'])) {
    // delete sql here
    $DELETE_ID = mysql_real_escape_string($_POST['delete']);
    unlink('../admin/testimonial_files/' . $row['Download']); // <----- HERE ------<

Link to comment
https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1160414
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.