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
https://forums.phpfreaks.com/topic/282313-syntax-check/
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 ?>" />

 

Link to comment
https://forums.phpfreaks.com/topic/282313-syntax-check/#findComment-1450416
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.