Forum Moderators: coopster
<form method="post" action="test.php">
<select name="OS" SIZE=3>
<option selected="selected">Windows
<option>Macintosh
<option>UNIX
<option>Amiga
<option>Next
<option>AppleII
</selectT>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
all looks good upto here as it should, I then tried this very basic PHP script to see if echoing a list was possible.
<?php
echo "you have selected ".$OS." from the list";
?>
I even tried
<?php
echo $OS;
?>
with no luck, so can anyone tell me where I am going wrong and how to get my little echo to work as i want it, for instance if I select Windows from the list and press submit i want it to display
you have selected Windows from the list.
I would appreciate a hand haha sorry if its novice but I am still starting out and aren't a php guru yet.
it should be now in $_POST['OS'];
if not, then
print_r($_POST);
<form method="post" action="test.php">
<select name="OS" SIZE=3>
<option selected="selected">Windows</option>
<option>Macintosh</option>
<option>UNIX</option>
<option>Amiga</option>
<option>Next</option>
<option>AppleII</option>
</select>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
I have a question regarding this, is it possible to list the contents of a directory in the list? and then do something like
unlink($_POST['OS']);
I have a directory of images and need PHP to delete the images, this seemes like a good way of doing it.
any help relating to this would be much appreciated.
there you've got a way to remove whole dir
<?php
function rmdirr($dir) {
if (substr($dir,-1)!= "/") $dir .= "/";
if (!is_dir($dir)) return false;
if (($dh = opendir($dir))!== false) {
while (($entry = readdir($dh))!== false) {
if ($entry!= "." && $entry!= "..") {
if (is_file($dir . $entry) ¦¦ is_link($dir . $entry)) unlink($dir . $entry);
else if (is_dir($dir . $entry)) rmdirr($dir . $entry);
}
}
closedir($dh);
rmdir($dir);
return true;
}
return false;
}
// Example:
$dir = "./MyDirectory/";
$res = rmdirr($dir); // Bye bye
if ($res == true) print "$dir got deleted.";
else print "Error while trying to delete $dir.";
?>
<?php
$dir = "/home/www/juttuffi/gallery/images";
$d = dir($dir);
while($entry = $d->read())
{
if ($entry!= "." && $entry!= ".."[smilestopper])
{
echo "<br>".$entry."<br>";
}
}
$d->close();
?>
will this work in a HTML list box form thingy?
sort of wrap the $entry in <option> tags?
kind of like this....
<form method="post" action="unlink.php">
<select name="OS" SIZE=3>
<?
$dir = "/home/www/juttuffi/gallery/images";
$d = dir($dir);
while($entry = $d->read())
{
if ($entry!= "." && $entry!= ".."[smilestopper])
{
echo "<option>".$entry."</option>";
}
}
$d->close();
?>
</select>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
anyone comment on the above?