Jump to content

unlink()


dsjoes

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

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
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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.