Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:25:35+00:00 2026-05-27T10:25:35+00:00

This is a rather complex problem so I will do my best to properly

  • 0

This is a rather complex problem so I will do my best to properly explain it.

I’m developing a HTML email template that will be uploaded into a flex-based web app, but I will try to use generic variables in my example.

Issue:
I have an image option where the a user can select from a library of images for their template. When the user selects the image there are 3 attributes that will load depending on the image selected, we will call them X, Y, Z. There are only six images available, and I have all of their URLs list as such:

$image_1 = '.../image1.jpg';
$image_2 = '.../image2.jpg';
$image_3 = '.../image3.jpg';

and so on w/ all the hardcoded urls being represented by a certain variable.

My code looks approximately like this:

//This is where the image will print after the selection is made and the page renders.

<img src="<?=$fields['mainImage']?>" /> //Pre-selection, and post image selection that <?=$fields['mainImage']?> will be the URL.

// This is where I try and add some logic directly below where the image loads. This if statement will actually trigger a variable to crawl a specific data array and print specific data that correlates to what image was selected (X, Y, Z, as stated above). But to not only keep it simple and check the functionality of the initial logic I am simply echoing three separate statements in this example.

<?
$fields['mainImage'] = $mainImage;

if ($mainImage = $image_1){

echo 'The first one works';

}
elseif ($mainImage = $image_2){

echo 'Yay the second data string loads!';

}
else 

echo 'O fart';

?>

Result:
In the above example, whether or not the user selects the 1st image or the 3rd image it loads ‘The first one works’ as if it can’t process any information beyond my initial if statement. Is there perhaps a syntax error I’m unaware of? Or maybe an error in my logic? This is a pretty basic example of a standard if statement, but I’m pretty stumped on why this isn’t functioning the way it should and would love some advice/feedback.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:25:35+00:00Added an answer on May 27, 2026 at 10:25 am

    You’re using the assignment operator (=) when you actually want to be using the comparison operator, ==.

    The assignment operator assigns the value of the operand on the right hand side of the argument to the variable on the left hand side. For example, you are doing this:

    if ($mainImage = $image_1){ // do stuff }
    

    This will copy the contents of $image_1 into $mainImage. $mainImage is then evaluated for truth – provided a suitable value (a non-zero integer, a not empty string or a TRUE boolean value) is provided, the first block will be entered. It is equivalent to writing if ($image_1).

    What you actually want is this:

    if ($mainImage == $image_1){ // do stuff }
    

    This will test the equality of $mainImage and $image_1 correctly, as you are trying to do above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've run into a rather strange problem. I have a div that is rotatable
I ran into a rather complex problem and I need the tree behavior to
I've been having this rather frustrating problem, and having failed so many times, I'm
I always found this rather annoying fact about applets, that they disappear if you
I recently ran into a quite complex problem and after looking around a lot
I have what I think is a rather complex problem. I have a C#
I have an application that loads lots of data into memory (this is because
I have run into a rather weird little problem. In the following code I
Have a (rather complex) app that works fine on iOS 4 but fails on
Found this rather strange bug in IE8; element.style.top is limited to 1342177 pixels. Even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.