Jump to content

syntax issues


Smudly

Recommended Posts

I'm having a slight problem setting an img tag in a variable. This variable will be called later in the page.

 

$avatar = $uploadrow['avatar'];
$avatarshow = "<img src=\'/avatars/$avatar\' width=\'100\' height=\'100\'>";

 

Now I am certain the problem is with my syntax in the avatarshow variable. I tested it by typing out the full name of the file, and it is shown just fine. But doing it this way causes problems. Any suggestions on fixing this code?

 

(I'm not getting any mysql errors)

Link to comment
https://forums.phpfreaks.com/topic/206610-syntax-issues/
Share on other sites

you're backslashing single quotes when the string is held within double quotes.

you only need to backslash double quotes within double quotes and single quotes within single quotes.

 

and for the directory avatars, you just need avatars/imageName.jpg, not /avatars/imagename.jpg

 

and i'm assuming "avatar" field in the database stores the image suffix - .jpg, .gif etc?

i.e.

$avatar = $uploadrow['avatar'];
$avatarshow = "<img src='avatars/$avatar' width='100' height='100'>";

Link to comment
https://forums.phpfreaks.com/topic/206610-syntax-issues/#findComment-1080595
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.