adam291086 Posted December 13, 2007 Share Posted December 13, 2007 My form variables are not being posted and i can't work out why. Here is the form <?php $ImageDirectory = "../upload/pictures/thumbnail"; echo '<form action="delete.php" method="post">'; $BigImage = "../upload/pictures/picture"; foreach (glob("$ImageDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}", GLOB_BRACE) as $image) { //remove .. for url $dir = str_replace("..", "", "$BigImage"); //get name for url $name = str_replace("$ImageDirectory", "", "$image"); //get name on it's own $fullname = str_replace("/", "", $name); echo '<br />'; echo $fullname; echo '<br />'; echo '<img src="'.$image.'">'; echo '<br />'; echo "www.adamplowman.co.uk".$dir.$name; echo '<br />'; echo "<a href=\"http://www.adamplowman.co.uk\cycling\admin".$dir.$name."\">View full Image</a>"; echo '<br />'; echo '<input type="radio" name="delete[".$image."]" value="Delete" />Delete'; echo '<br />'; echo '<br />'; echo '<input type="submit" value="Delete Selected">'; echo '<br />'; echo '<br />'; } ?> and this is the delete script. The variable adam is no where to be seen <?php $adam = $_POST['delete']; foreach($adam as $key => $value){ if($value == "1"){ unlink($key); } } echo $adam; ?> Quote Link to comment Share on other sites More sharing options...
stevesimo Posted December 13, 2007 Share Posted December 13, 2007 To post the values you will need to assign them to a form object such as a hidden field. The PHP variables wont be be passed from page to page so using hidden fields is a useful way to achieve this. Hope this helps Steve Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 i am confused? can you show an example? Quote Link to comment Share on other sites More sharing options...
stevesimo Posted December 13, 2007 Share Posted December 13, 2007 on the following html form notice the input of type hidden. You can have multiple hidden fields on a form. These arent visible to the user but are passed along with all the other visible elements such as the textboxes etc. <form action="process.php" method="post" name="myform" id="myform"> <p>Name <input type="text" name="textfield"> </p> <p> <input type="submit" name="Submit" value="Submit"> <input name="somevalue" type="hidden" id="somevalue" value="<?PHP echo $somevalue; ?>"> </p> </form> [code] When the form is posted, your script at the other end can simply use $_post[somevalue] to read the values from the names of all the hidden fields. Let me know if this helps. Steve [/code] Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 well can't i just do echo '<input type="radio" name="delete[".$image."]" value="1" />Delete'; then in the delete page do foreach($adam as $key => $value){ if($value == "1"){ unlink($key); } } echo $HTTP_POST_VARS['delete']; Quote Link to comment Share on other sites More sharing options...
stevesimo Posted December 13, 2007 Share Posted December 13, 2007 this wont work because it is the value property you need to be posting, not the name. Otherwise when you are trying to read in the post at the other end, how do you know what the field is going to be called? echo '<input type="radio" name="delete[".$image."]" value="1" />Delete'; [code] really should be written like this: [code] echo '<input type="radio" name="deleteimage" value="<?PHP $imageid ?>" />Delete'; [code] This way you always know that the name of the value is deleteimage but the value can be whatever it chooses. [/code][/code][/code] Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 I would use image id the problem being i am not using a database. I am using open directory. I am trying to set up a delete function. This is takes the image name and unlinks it. Hence the reason the name of the check box = the image name. and value = 1. So if value =one unlink image. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 you code should be echo '<input type="radio" name="delete[]" value="'.$image.'" />Delete '.$image; then in the delete page do $arrImages = $_POST['delete']; foreach($arrImage as $key => $value){ unlink($value); } echo $HTTP_POST_VARS['delete']; Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 edit ..... Actually no information is being passed across and i dont know why? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 do you have your form tags ? started and ended properly ? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 yep here is the code <?php $ImageDirectory = "../upload/pictures/thumbnail"; echo '<html>'; echo '<body>'; echo '<form action="delete.php" method="post">'; $BigImage = "../upload/pictures/picture"; foreach (glob("$ImageDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}", GLOB_BRACE) as $image) { //remove .. for url $dir = str_replace("..", "", "$BigImage"); //get name for url $name = str_replace("$ImageDirectory", "", "$image"); //get name on it's own $fullname = str_replace("/", "", $name); echo '<br />'; echo $fullname; echo '<br />'; echo '<img src="'.$image.'">'; echo '<br />'; echo "www.adamplowman.co.uk".$dir.$name; echo '<br />'; echo "<a href=\"http://www.adamplowman.co.uk\cycling\admin".$dir.$name."\">View full Image</a>"; echo '<br />'; echo '<input type="radio" name="delete[]" value="'.$image.'" />Delete '.$image; echo '<br />'; echo '<br />'; echo '<input type="submit" value="Delete Selected">'; echo '<br />'; echo '<br />'; } echo '</from>'; echo '</html>'; echo '</body>'; ?> Quote Link to comment 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.