avelampudi avelampudi - 4 years ago 140
HTML Question

put checkboxes next to items in table html php

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);
?>

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download