New to php..using books, studying lots of code and taking in all information I can to learn the language. Having fun, but of course having some issues as I learn. Okay I have an edit page where a user can modify one of their ad listings. Each ad can have up to four pictures, but they are not required. Here is the code that displays the pictures on the edit page <?php echo '<div id ="editpictures">'; if (!empty($row['picture'])) { echo '<a href="'. $picurl . $row['picture'] . '" rel="' . $greybox . '" title="' .$row['year'] ." ". $row['manufacturer'] ." ". $row['model'] . '"</a><img id="pic1a" src="'. $thumb . $row['picture'] . $size .'" />'; } if (!empty($row['picturetwo'])) { echo '<a href="'. $picurl . $row['picturetwo'] . '" rel="' . $greybox .'" title="' .$row['year'] ." ". $row['manufacturer'] ." ". $row['model'] . '"</a><img id="pic2a" src="'. $thumb . $row['picturetwo'] . $size .'" />'; } if (!empty($row['picturethree'])) { echo '<a href="'. $picurl . $row['picturethree'] . '" rel="' . $greybox .'" title="' .$row['year'] ." ". $row['manufacturer'] ." ". $row['model'] . '"</a><img id="pic3a"src="'. $thumb . $row['picturethree'] . $size .'" />'; } if (!empty($row['picturefour'])) { echo '<a href="'. $picurl . $row['picturefour'] . '" rel="' . $greybox . '" title="' .$row['year'] ." ". $row['manufacturer'] ." ". $row['model'] . '"</a><img id="pic4a" src="'. $thumb . $row['picturefour'] . $size .'" />'; } echo '</div>'; ?> PHP: Now, because this is the edit page, the user has the option to delete their pictures and then replace them. If the user clicks the remove button, a script is executed that deletes the picture and then replaces the picture with a file input field so they can upload a new one if they so choose. The problem I have is if I then refresh the page or come back later, it will only show pictures in the database up until the one that has been deleted. Isn't my if statement structured so that even if the $row for the given picture is empty it will still move on and check the next statement? Example: "picturetwo" gets deleted. The next time you come to the edit page, it will only show "picture". I want it to show "picture", "picturethree", and "picturefour" Any help on getting this done or improving the code is much appreciated. Thanks!
Your code should work correctly. <?php if(isset($_GET['test'])) { echo "1"; } if(isset($_GET['testing'])) { echo "2"; } if(isset($_GET['blah'])) { echo "2"; } ?> PHP: Would do the same thing. http://site.com/?testing would still echo 2 even if the other two are empty.
I see. Well I have some javascript working in there too (very new to javascript). Basically I am using javascript to make the old picture and a "remove" button disappear and then get replaced by the file input field. I am using styles and such to make this happen...I wonder if the javascript is causing some sort of issue. Thanks for verifying the php.
How about setting each image in it's own DIV with it's individual ID so if it's deleted you can simply change the innerHTML of the entire but specific div to the upload image form.
Thanks for the suggestion, that might be a better way accomplish what I am trying to do, but i did solve the original problem. It was afterall, the javascript that was my issue. When a picture would get deleted, my script would still look for that class or id and when it couldnt find it, then the rest of my javascript didnt execute...at least that is what I can figure to the best of my knowledge happened. So I simply added an if statement to check for each element first and that has solved my problem: The javascript below for those interested The code that didnt work, this code would repeat for each of the four pictures and their supporting elements. Basically the script showed each picture with a remove button next to it and then when the user hits the remove button the picture and the remove button were replaced by the file input. function fancybuttons() { document.getElementById("button1").style.display = "block"; document.getElementById("pic1a").style.display = "block"; document.getElementById("button1").onclick = function(){ document.getElementById("button1").style.display = "none"; document.getElementById("pic1a").style.display = "none"; document.getElementById("browse1").style.display = "block"; } Code (markup): Here is what did work function fancybuttons() { if (document.getElementById("pic1a")) { document.getElementById("button1").style.display = "block"; document.getElementById("pic1a").style.display = "block"; document.getElementById("button1").onclick = function(){ document.getElementById("button1").style.display = "none"; document.getElementById("pic1a").style.display = "none"; document.getElementById("browse1").style.display = "block"; } } Code (markup): Now I guess to continue the PHP discussion, Ill ask another question regarding how I currently have this part of my site working. I wanted to create a seemless interface where the user clicked to remove the picture and it actually was deleted from the Database right then AND the input field came right back up so they could replace the deleted picture with a new one if they chose to do so. So the whole javascript code is actually this: function fancybuttons() { if (document.getElementById("pic1a")) { document.getElementById("button1").style.display = "block"; document.getElementById("pic1a").style.display = "block"; document.getElementById("button1").onclick = function(){ document.getElementById("button1").style.display = "none"; document.getElementById("pic1a").style.display = "none"; document.getElementById("browse1").style.display = "block"; document.createElement("IFRAME"); ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "/interact/<?php echo $junkone.$junktwo; ?>"); ifrm.style.width = "0px"; ifrm.style.height = "0px"; document.body.appendChild(ifrm); } } Code (markup): So I am basically just creating an invisible Iframe where the php delete script can be executed and the user can continue to edit the ad until all their changes have been made. Any suggestions on other strategies I could take to accomplish this? I am okay with how it is right now, it actually works quite well, but I also realize there could be better ways to do it.