Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP echo html if session = specific variable

Posted on 2008-06-11
4
Medium Priority
?
1,046 Views
Last Modified: 2013-11-13
Hello,

I'm new to php, below I am trying to echo specific html based on the session variable set by the previous page.  Doesn't work, entire page is blank now.  Any help is appreciated.

Note: I removed m;uch of the white space in code below, after pasting into, formatting was lost.
<?php
 if ($_SESSION['country'] = 'usa_en'{
  echo
    // US 
    <span class=\"oneField\">
    <label for=\"carrier\" class=\"preField\">Please Select Your Carrier:</label><br />
<select id=\"carrier\" name=\"carrier\" class=\"formfield\" onchange=\"ChangeDropdowns(this.value); getPhones(this)\">
<option value=\"\">Select a Carrier</option>
<option value=\"att\">ATT</option>
<option value=\"tmobile\">T-Mobile</option>
<option value=\"other\">Other</option>
</select><br />
<div id=\"phones\" style=\"display:none;\">
<label for=\"myphone\" class=\"preField\">Select Your Phone:</label><br />
<select id=\"myphone\" name=\"myphone\" class=\"formfield\" onchange=\"showPlans(this.name)\">
</select>
</div>
</span><br />
           
<div id=\"plans\" class=\"right_pg2\" style=\"display:none;\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_us\" />Unlimited $19.95/month<br />
</p>
</div> 
<br />
// End US 
}
else {
echo
// Other countries div 
<div class=\"right_pg2\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_nl\" />Unlimited $19.95/month<br />
</p>
</div> 
// end other countries div 
} 
?>

Open in new window

0
Comment
Question by:vrmetro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 1200 total points
ID: 21761778
Try this minor adjustment:

  if ($_SESSION['country'] == 'usa_en'

The single equals sign ('=') sets the value of a variable. If you want to find out if something "does equal" something else, you can use the double equals sign ('==').

Also note that I added the appropriate quotes around your echo statements:
<?php
 if ($_SESSION['country'] = 'usa_en'{
  echo
    // US 
    "<span class=\"oneField\">
    <label for=\"carrier\" class=\"preField\">Please Select Your Carrier:</label><br />
<select id=\"carrier\" name=\"carrier\" class=\"formfield\" onchange=\"ChangeDropdowns(this.value); getPhones(this)\">
<option value=\"\">Select a Carrier</option>
<option value=\"att\">ATT</option>
<option value=\"tmobile\">T-Mobile</option>
<option value=\"other\">Other</option>
</select><br />
<div id=\"phones\" style=\"display:none;\">
<label for=\"myphone\" class=\"preField\">Select Your Phone:</label><br />
<select id=\"myphone\" name=\"myphone\" class=\"formfield\" onchange=\"showPlans(this.name)\">
</select>
</div>
</span><br />
           
<div id=\"plans\" class=\"right_pg2\" style=\"display:none;\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_us\" />Unlimited $19.95/month<br />
</p>
</div> 
<br />";
// End US
}
else {
echo
"// Other countries div 
<div class=\"right_pg2\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_nl\" />Unlimited $19.95/month<br />
</p>
</div> ";
// end other countries div "
} 
?>

Open in new window

0
 
LVL 24

Expert Comment

by:glcummins
ID: 21761784
Here it is again, with the double-equals corrected:
<?php
 if ($_SESSION['country'] == 'usa_en'{
  echo
    // US 
    "<span class=\"oneField\">
    <label for=\"carrier\" class=\"preField\">Please Select Your Carrier:</label><br />
<select id=\"carrier\" name=\"carrier\" class=\"formfield\" onchange=\"ChangeDropdowns(this.value); getPhones(this)\">
<option value=\"\">Select a Carrier</option>
<option value=\"att\">ATT</option>
<option value=\"tmobile\">T-Mobile</option>
<option value=\"other\">Other</option>
</select><br />
<div id=\"phones\" style=\"display:none;\">
<label for=\"myphone\" class=\"preField\">Select Your Phone:</label><br />
<select id=\"myphone\" name=\"myphone\" class=\"formfield\" onchange=\"showPlans(this.name)\">
</select>
</div>
</span><br />
           
<div id=\"plans\" class=\"right_pg2\" style=\"display:none;\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_us\" />Unlimited $19.95/month<br />
</p>
</div> 
<br />";
// End US
}
else {
echo
"// Other countries div 
<div class=\"right_pg2\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_nl\" />Unlimited $19.95/month<br />
</p>
</div> ";
// end other countries div
} 
?>

Open in new window

0
 
LVL 14

Assisted Solution

by:Ali Kayahan
Ali Kayahan earned 800 total points
ID: 21761830
if the one above doesnt work try this also ;

<?php
 if ($_SESSION['country'] == 'usa_en'){
  echo
    // US 
    "<span class=\"oneField\">
    <label for=\"carrier\" class=\"preField\">Please Select Your Carrier:</label><br />
<select id=\"carrier\" name=\"carrier\" class=\"formfield\" onchange=\"ChangeDropdowns(this.value); getPhones(this)\">
<option value=\"\">Select a Carrier</option>
<option value=\"att\">ATT</option>
<option value=\"tmobile\">T-Mobile</option>
<option value=\"other\">Other</option>
</select><br />
<div id=\"phones\" style=\"display:none;\">
<label for=\"myphone\" class=\"preField\">Select Your Phone:</label><br />
<select id=\"myphone\" name=\"myphone\" class=\"formfield\" onchange=\"showPlans(this.name)\">
</select>
</div>
</span><br />
           
<div id=\"plans\" class=\"right_pg2\" style=\"display:none;\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_us\" />Unlimited $19.95/month<br />
</p>
</div> 
<br />";
// End US
}
else {
echo
"// Other countries div 
<div class=\"right_pg2\">
<p class=\"notice\">
<input type=\"checkbox\" name=\"plan\" id=\"plan\" value=\"1995_mob_nl\" />Unlimited $19.95/month<br />
</p>
</div> ";
// end other countries div
} 
?>

Open in new window

0
 

Author Closing Comment

by:vrmetro
ID: 31466230
gl helped me understand the "=" symbol, ali helped with the final ")" we were missing; thank you very much!!!
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Introduction to Processes

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question