dsjoes Posted January 9, 2011 Author Share Posted January 9, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157145 Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 $row isn't set, therefore this and other similar values are empty <?php echo $row['id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157164 Share on other sites More sharing options...
dsjoes Posted January 9, 2011 Author Share Posted January 9, 2011 i thought that this did that $row = mysql_fetch_assoc($result1); Â when i use this <?php while($row=mysql_fetch_array($result1)){Â ?> table part here } Â i get the error Parse error: syntax error, unexpected $end Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157184 Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157185 Share on other sites More sharing options...
dsjoes Posted January 9, 2011 Author Share Posted January 9, 2011 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  Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157189 Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 $result1 is the result of deleting. i think you want $result  i highly recommend that you indent your php code so that the logic is more apparent. Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157190 Share on other sites More sharing options...
dsjoes Posted January 9, 2011 Author Share Posted January 9, 2011 $result1 is the result of deleting. i think you want $result  i highly recommend that you indent your php code so that the logic is more apparent.  nothing changed it is still the same Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157191 Share on other sites More sharing options...
dsjoes Posted January 9, 2011 Author Share Posted January 9, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157193 Share on other sites More sharing options...
dsjoes Posted January 10, 2011 Author Share Posted January 10, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157434 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 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 Â what's on line 48? Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157439 Share on other sites More sharing options...
dsjoes Posted January 10, 2011 Author Share Posted January 10, 2011 this </tr><?php while($row = mysql_fetch_array($sql) or die("Query Failed: $sql " . mysql_error()))Â ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157464 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 i have added the error bit <?php while($row = mysql_fetch_array($sql) or die("Query Failed: $sql " . mysql_error()))Â ?> Â why?? Â Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157525 Share on other sites More sharing options...
dsjoes Posted January 10, 2011 Author Share Posted January 10, 2011 to see if it said anything different it isn't on any more i took it off once i posted on here Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157571 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 so this line no longer reads like this? can we see the latest code? Â this </tr><?php while($row = mysql_fetch_array($sql) or die("Query Failed: $sql " . mysql_error()))Â ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157597 Share on other sites More sharing options...
dsjoes Posted January 10, 2011 Author Share Posted January 10, 2011 <?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)) ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157611 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 $sql is not a valid MySQL result. where is $sql defined? Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1157638 Share on other sites More sharing options...
jaikob Posted January 11, 2011 Share Posted January 11, 2011 $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); Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1158081 Share on other sites More sharing options...
dsjoes Posted January 11, 2011 Author Share Posted January 11, 2011 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)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1158101 Share on other sites More sharing options...
jaikob Posted January 12, 2011 Share Posted January 12, 2011 Whoops. I got my code mixed up, use this: Â <?php $row = mysql_fetch_assoc($result); ?><?php do { ?> <?php } while($row = mysql_fetch_assoc($result)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1158507 Share on other sites More sharing options...
dsjoes Posted January 12, 2011 Author Share Posted January 12, 2011 it is still the same Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1158578 Share on other sites More sharing options...
dsjoes Posted January 14, 2011 Author Share Posted January 14, 2011 bump anyone Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1159471 Share on other sites More sharing options...
dsjoes Posted January 16, 2011 Author Share Posted January 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1160370 Share on other sites More sharing options...
Pikachu2000 Posted January 16, 2011 Share Posted January 16, 2011 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 ------< Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1160414 Share on other sites More sharing options...
dsjoes Posted January 16, 2011 Author Share Posted January 16, 2011 no i am not getting other warnings and i know that that unlink is in the wrong place but i have left it because i don't know where to put it and that is where the jaikob put it when he redesigned the script to implement it   Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1160438 Share on other sites More sharing options...
Pikachu2000 Posted January 16, 2011 Share Posted January 16, 2011 I'll try to look it over in detail later this evening. Don't have time at the moment, though. Quote Link to comment https://forums.phpfreaks.com/topic/223250-unlink/page/2/#findComment-1160440 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.