LunarIsSexy Posted September 20, 2013 Share Posted September 20, 2013 I'm very bad with checking Syntax and I confused myself here D: Anybody able to help? Function: <?php require('main.php'); require('connect.php'); $id=$_SESSION['id']; $result3 = mysql_query("SELECT * FROM photo where id='$id'"); while($row3 = mysql_fetch_array($result3)) $image=$row3['filename']; ?> Calling the image: <img src=" <?php if(empty($image)){ echo "upload/your-photo.jpg"; }else{ echo "site_images/" + $id + "/" + $image; }?>" alt="" width="85" height="85"> Basically it will save the file uploaded into the database with the filename and the id of the user, it will then make a directory inside site_images named after the ID of the user and it will move the image to that folder. Then to show the image I made it check if the user never uploaded a photo, and if they haven't to show the default. If they have uplaoded a photo it will set the source of the images to "site_images/$id/$image" basically. This works perfectly if I put it like this. <img src="/site_images/<?php echo $id ?>/<?php echo $image ?>"> Any idea what I did wrong or whats wrong with my syntax? Quote Link to comment Share on other sites More sharing options...
LunarIsSexy Posted September 20, 2013 Author Share Posted September 20, 2013 Update: The image its showing up with is a link to the folder 15, not inside /site_images/ and without the image name. D: Quote Link to comment Share on other sites More sharing options...
TOA Posted September 20, 2013 Share Posted September 20, 2013 (edited) php uses .(dot) concatenation, not + echo "site_images/" . $id . "/" . $image; But I would do it in a more readable fashion; like this: $src = (empty($image)) ? "upload/your-photo.jpg" : "site_images/$id/$image"; <img src="<?php echo $src ?>" /> Edited September 20, 2013 by TOA 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.