Jump to content

load image


gobblegob

Recommended Posts

hello coders,

This is my first post here, well actually with PHP as i have only been messing with it for 1 week, but i do have good knowledge of vb.net, anyways....

Then problem i have is an extremely basic and embarrassing  :-[       

after i send an email with my script if successful then show one image if unsuccessful show another.

 

This is my code that works...

<?php echo $mail_sent ? "An email has been sent to you." : "Mail has failed.";?>

 

This is what i am trying to do....

<?php echo $mail_sent ? "An email has been sent to you.<img src="images/green_tick.gif" width="20" height="20" />" : "Mail has failed.<img src="images/failed.gif" width="20" height="20" />"";?>

Link to comment
Share on other sites

As i'm sure what is a necessity of programming language, is maintaining the integrety of strings. PHP is based off of C, So it's not too alien, Just escape:

<?php 
  echo $mail_sent ? "An email has been sent to you.<img src=\"images/green_tick.gif\" width=\"20\" height=\"20\" />" : "Mail has failed. <img src=\"images/failed.gif\" width=\"20\" height=\"20\" />";
?>

Or of course you can use single quotes, either to wrap or to use within double quotes:

<?php 
  echo $mail_sent ? 'An email has been sent to you.<img src="images/green_tick.gif" width="20" height="20" />' : 'Mail has failed.<img src="images/failed.gif" width="20" height="20" />';
?>

 

 

Link to comment
Share on other sites

Thanks alot guys  :D , so what does the backslash do ? src=\  please dont flame me lol

 

Oh, I came from a VB.NET background from 4-5 years back but must've forgotten how the more simple things were done.

 

A backslash is an escape entity, Well, best I show you a tutorial on them:

http://www.htmlite.com/php008.php

 

If you're using double quotes within double quotes, they need to be escaped from the current context, Such as:

print "This is a double quote: \"  <---";

 

Dollar signs have precedence in double quotes, so variable can be displayed:

$var = "foo";
print "\$var = $var"; //Will print: $var = foo

 

I'd really recommend looking up some basic PHP tutorials such as in Tizag, As you can trust from an ex-.NET programmer C is much different in its syntax than VB.

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.