Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

PHP Parse error: syntax error, unexpected T_IF


  • Please log in to reply

#1
wf4

wf4

    Member

  • Member
  • PipPip
  • 28 posts
Hello Folks!
The purpose of this code is to extract info from my database and wrap the results in XML tags.
What i am trying to do is return a "1" or "0" depending on whether the "parent4_cat" = "Commercial".

This works fine:
$xml_file.="\t\t" . "<VARIANT>".htmlspecialchars($product['parent4_cat'])."</VARIANT>\n";
which would give an output of:
<VARIANT>Petrol</VARIANT>

This gives me the Parse error: syntax error, unexpected T_IF
$xml_file.="\t\t" . "<COMMERCIAL>".htmlspecialchars.if($product['parent4_cat'] = "Commercial"){ "0";}else{"1";};."</COMMERCIAL>\n";
which i want to output:
<COMMERCIAL>1</COMMERCIAL> (or <COMMERCIAL>0</COMMERCIAL>)

I hope this makes sense. Any help would be appreciated.

Kind regards,
Will.
  • 0

Advertisements


#2
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
Hi Will,

I think that's because the if gets read when the program is expecting the string that htmlspecialchars tries to evaluate.

Not sure how exactly you want your output, but try this:

if($product['parent4_cat'] == "Commercial")  { $bit = "0"; } else { $bit="1"; }

$xml_file.="\t\t" . htmlspecialchars("<COMMERCIAL>" .  $bit . "</COMMERCIAL>") . "\n";

  • 0

#3
wf4

wf4

    Member

  • Topic Starter
  • Member
  • PipPip
  • 28 posts
Hi Metallica...
Your fix stopped the parse error! I had to tweek it further as the XML tags were displayed as text, not tags....

This fixed it...

if($product['parent4_cat'] == "Commercial")  { $bit = "0"; } else { $bit="1"; }

$xml_file.="\t\t" . "<COMMERCIAL>" . htmlspecialchars( $bit  ) . "</COMMERCIAL>\n";

THANK YOU!!!

Would it be possible to join your administration team? I'd love to help out....
  • 0

#4
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
Glad I could help. :)

If you make yourself useful on the site, you'll inevitably get noticed sooner or later. :)
  • 0

#5
wf4

wf4

    Member

  • Topic Starter
  • Member
  • PipPip
  • 28 posts
Great Stuff...

I'm looking at your javascript problem now....

What you planning on using it for?
  • 0

#6
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
Long story, but in short I want to incorporate it into a php form where people can put checkmarks for each department that needs to be informed about changes in our program.

If I use only value=1 I can count afterwards how many departments need to be informed, but not which ones. :)
If I can use the "doubled" values I can break down the number in the database and see which ones exactly.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP