Jump to content

Syntax - Check?


LunarIsSexy

Recommended Posts

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?

Link to comment
Share on other sites

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 by TOA
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.