thefollower Posted September 16, 2008 Share Posted September 16, 2008 My "file exist" function doesn't seem to work.. it claims the image is found when i quite obviously do not have the image on my server, so it shows well nothing... other than test =/ This is what i have: <?php While($row = mysql_fetch_assoc($Get)){ $Image = $row['Image']; $Check = '/images/userprofiles/'.$Image; $RecordID = $row['RecordID']; if (file_exists($Check)) { ?> <img src="/images/userprofiles/<?php echo $Image;?>" width="100px" height="150px"> <br>TEST<br> <?php }Else{ $DELETE = mysql_query("DELETE FROM userimages WHERE RecordID='$RecordID'") Or die(mysql_error()); } } ?> What did i do wrong? Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted September 16, 2008 Share Posted September 16, 2008 Im betting on $Image having no value Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 16, 2008 Share Posted September 16, 2008 Edit: neil.johnson beat me to it, but only because I was writing some code. I'm assuming the 'Image' value from the query is returning a null or empty value. So, file_exists() is returning true because the FOLDER '/images/userprofiles/' exists! While($row = mysql_fetch_assoc($Get)) { if ($row['Image']) //Ensure a value was returned { if (file_exists('/images/userprofiles/'.$row['Image'])) { echo "<img src=\"/images/userprofiles/<?php echo $Image;?>\" width=\"100px\" height=\"150px\">\n"; echo "<br>TEST<br>\n"; } else { $query = "DELETE FROM userimages WHERE RecordID='{$row['RecordID']}'"; mysql_query($query) or die(mysql_error()); } } } FYI: This makes no sense $DELETE = mysql_query("DELETE FROM userimages WHERE RecordID='$RecordID'") What do you plant to do with the variable $DELETE? Unless the query is returning data, there is no need to assign a variable to the query call. Also, I changed the script to reduce some of the variables created. In most instances it makes no sense to create a variable just to use it only once or twice (e.g. $Image & $RecordID) Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 16, 2008 Share Posted September 16, 2008 @mjdamato you cannot use PHP tags/code within an echo: echo "<img src=\"/images/userprofiles/<?php echo $Image;?>\" width=\"100px\" height=\"150px\">\n"; That line should be echo "<img src=\"/images/userprofiles/$Image\" width=\"100px\" height=\"150px\">\n"; Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 17, 2008 Share Posted September 17, 2008 @mjdamato you cannot use PHP tags/code within an echo: Yeah, well so I made a mistake with a copy paste. So sue me. 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.