0

I have a webpage that allows users to view the log files on the SD card that's on my Beaglebone. On this webpage, is a table with hyperlinks to the log files so that when the user wants to view them, they click on the specific log file and it downloads to their local system. Now, I want to put checkboxes next to these items in my HTML table so that the user can delete them off the beaglebone server when they want to.

The code was working perfectly before I tried to put the table into a form for the checkboxes. It showed up like this: Before adding the form to delete

But after adding the form, nothing shows up. The file unlink.php refers to the code that deletes the files. Here's the code:

<?php

$url = $_SERVER['DOCUMENT_ROOT'];

$path = "/var/www/html/Logs";
$dh = opendir($path);

$k=0;
$foo=True;

while (($file = readdir($dh)) !== false) {
    if($file != "." && $file != "..") {
    #echo "<a href='Logs/$file'>$file</a>";
    if($k==0 || $k %7==0){
        $col .= "<tr><td><input type="checkbox" name="file[]" value="Logs/$file"><a href='Logs/$file'>$file</a><br /></td>";
    }
    else if($k %7==6){
        $col .= "<td><input type="checkbox" name="file[]" value="Logs/$file"><a href='Logs/$file'>$file</a><br /></td></tr>"; 
    }
    else{
        $col .= "<td><input type="checkbox" name="file[]" value="Logs/$file"><a href='Logs/$file'>$file</a><br /></td>";
    }

    $k++;

}

}
echo "<form action="unlink.php" method="get"><table>$col</table><input type="submit" name="formSubmit" value="Submit" /></form> ";

closedir($dh);
?> 
avelampudi
  • 316
  • 2
  • 6
  • 16

1 Answers1

1

The line where you echo out the form tag and table, you need to either escape all the double quotes in your string or change them all to single quotes. You have strings like "<form method="get">..." and are using double quotes within double quotes which will cause an error. It should be something more like:

echo "<form action='unlink.php' method='get'><table>$col</table><input type='submit' name='formSubmit' value='Submit' /></form> ";

If you viewed the error log that php writes to, you would see this error.

Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43
  • I tried this, it doesn't help. Where does php write the errors to? – avelampudi Feb 06 '17 at 20:56
  • 1
    You also need to escape/change the quotes on all the values getting added to $col – Andy Feb 06 '17 at 20:57
  • 1
    You also have same issue on all the lines with the checkboxes. Look at the syntax highlighting in your post. See how the colors change from red (string) to black/teal? That is because those are not part of a string. – Jonathan Kuhn Feb 06 '17 at 20:57
  • 1
    OH, I did not realize double quotes could cause an error – avelampudi Feb 06 '17 at 21:01
  • Well, since you are using double quotes for your string, when you hit another double quote in the string php thinks your string has ended. This could mean you plan on concatenating with another string or variable or it is just the end of the string/line. – Jonathan Kuhn Feb 06 '17 at 21:06