sean14592 Posted April 12, 2008 Share Posted April 12, 2008 Hi, I have stored my image name in db after uploading it, so this is all well for the first 2 images as they are complusary. Though for example image 8 that is not required. How do I stop it from being shown if the database field is empty? <?php $connect = mysql_connect($host,$username,$password) or die("Error connecting to Database!". mysql_error()); mysql_select_db($database,$connect) or die("cannot select database!".mysql_error()); //photo8 $check8 = mysql_query("select photo8url from properties where id='$id'") or die(mysql_error()); $result8 = mysql_query($check8); if (mysql_num_rows($check8) > 0) { $a_record = mysql_fetch_array($check8); $photo8url = $a_record['photo8url']; $photo8url = preg_replace('/\s+/', '%20', $photo8url); } ?> <?php if ($result8 = ""){} else{ echo ("<img src=". $id ."/images/".$photo8url." width=\"235\" border=\"1\">"); } ?> Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 Please someone, I really need some help. If you want yu can contact me on Xfire = sean14592 Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 12, 2008 Share Posted April 12, 2008 SQL Injections could easily be done with your script! Check if the id is numeric otherwise DON'T execute this page. To your quest: <?php $res = mysql_query('YOUR QUERY'); if (mysql_num_rows($res)) { //View image }else { echo 'Image not found'; } ?> Quote Link to comment Share on other sites More sharing options...
porta325 Posted April 12, 2008 Share Posted April 12, 2008 Try $check8 = mysql_query("select photo8url from properties where id='$id'" AND yourimagefiels IS NOT NULL) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 Hi, I have tried the following: $res = mysql_query("select photo8url from properties where id='$id' AND photo8url =' ' ") or die(mysql_error()); if (mysql_num_rows($res)) { echo ("<img src=". $id ."/images/".$photo8url." width=\"235\" border=\"1\">"); }else { echo 'Image not found'; } Though its trying to show a image when the data base is empty. Cheers Sean Preston Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 Please somebody, I have proberly just missed something stupidly. Sean Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 I have also tried.... $connect = mysql_connect($host,$username,$password) or die("Error connecting to Database!". mysql_error()); mysql_select_db($database,$connect) or die("cannot select database!".mysql_error()); //photo1 $check1 = mysql_query("select photo1url from properties where id='$id'") or die(mysql_error()); $result1 = mysql_query($check1); if (mysql_num_rows($check1) > 0) { $a_record = mysql_fetch_array($check1); $photo1url = $a_record['photo1url']; $photo1url = preg_replace('/\s+/', '%20', $photo1url); } else { $photo1_check = "1"; } if ($photo1_check = "1") { echo ("no image!!!!!!"); }else { echo ("<img src=". $id ."/images/".$photo1url." width=\"235\" border=\"1\">"); } ?> This shows "no image" even if a image has been stored,lol This is driving me crazyyyy! Sean Preston Quote Link to comment Share on other sites More sharing options...
CrustyDOD Posted April 12, 2008 Share Posted April 12, 2008 select photo8url from properties where id='$id' AND photo8url <> '' if "photo8url" contains something the mysql_num_rows will be 1 else 0 Quote Link to comment Share on other sites More sharing options...
robrave Posted April 12, 2008 Share Posted April 12, 2008 maybe the image is cached on the browser? Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 maybe the image is cached on the browser? Nope, it aint that. Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 select photo8url from properties where id='$id' AND photo8url <> '' if "photo8url" contains something the mysql_num_rows will be 1 else 0 Tried, dosent work :( Thanks anyway Sean Preston Quote Link to comment Share on other sites More sharing options...
sean14592 Posted April 12, 2008 Author Share Posted April 12, 2008 I have figued out (so I think) that somet is wrong here $check8 = mysql_query("select photo8url from properties where id='$id'") or die(mysql_error()); if (mysql_num_rows($check8) > 0) { $a_record = mysql_fetch_array($check8); $photo8url = $a_record['photo8url']; $photo8url = preg_replace('/\s+/', '%20', $photo8url); } else { $photo8_check = "1"; } because if I.... echo $photo8_check; I should see the number '1', as in the database field Photo8url using the id is completely empty. Do you understand what I mean? Cheers Sean Quote Link to comment Share on other sites More sharing options...
CrustyDOD Posted April 12, 2008 Share Posted April 12, 2008 Before mysql_query line put this: echo "select photo8url from properties where id='$id'"; Then you will see if $id even is set to something. 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.