Jump to content

Space in If Else statement.


yourfreemp4player

Recommended Posts

Hi,

 

I have a space in the word I need to use in an If Else statement and its killing my page.

 

This is what I'm putting on my site...

 

if($session->prize==Option 1){

    echo " <img src=\"images/ipodstyle.jpg\"> ";}else{ }

 

It says "Parse error: syntax error, unexpected ';' in /home/freemp4/public_html/index.php on line 62"

 

However, if I was to change the word to "Option1", it works, but it doesn't help me, since I need the space in there...

 

Is there anything I can do besides get rid of the space?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/151694-space-in-if-else-statement/
Share on other sites

Well, you could use option 1 as a string of "Option 1" but it all depends on how you are using it and how you make it.

 

To me, I would do:

$option = 'Option 1';

if($session->prize == $option)

 

OR if Option changes,

$option = 'Option ' . $num; // However you give the number (loop, db, etc.)

if($session->prize == $option)

($session->prize==Option 1)

 

Invalid code.

 

If you want to check the contants in $session->prize to contain 'Option 1' then you need to place 'Option 1' inside a variable and check that or enclose double/single quotes around it and check it that way.

 

That's presuming 'Option 1' is exactly what you want to check against.

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.