Jump to content

[SOLVED] Help With "Switch"


Paulio

Recommended Posts

Hey, im having some trouble with my code, ive been using the php "switch", i used the free hosting from lycos while i tested the website and all was fine (using "index.php?x=corporate" etc...), now i have changed to a proper cpanel webhost (has php) the page always comes up with the "default" code i.e.

default: 
echo("<div class='title'>Home</div>");
include("content_home.php");
}

 

below is the code from my page and any help would be much appreciated.

 

thanks, Paul

<html>
<head>
<title>test.com</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="script.js"></script>
</head>

<body>

<?php
switch ($x)
{
case corporate:
echo("<div class='title'>Corporate</div>");
include("content_corporate.php");
break;

case business: 
echo("<div class='title'>Business</div>");
include("content_business.php"); 
break;

case gallery:
echo("<div class='title'>Gallery</div>"); 
include("content_gallery.php"); 
break; 

case weddings:
echo("<div class='title'>Wedding Car Service</div>");
include("content_weddings.php");
break;

case contact:
echo("<div class='title'>Contact Us</div>");
include("content_contact.php");
break;

case contactform:
echo("<div class='title'>Contact Form</div>");
include("content_contactform.php");
break;

case sent:
echo("<div class='title'>Message Sent</div>");
include("content_sent.php");
break;

default: 
echo("<div class='title'>Home</div>");
include("content_home.php");
}
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/
Share on other sites

i have now used quotes and it didnt do anything

 

<?php
switch ($x)
{
case "corporate":
echo("<div class='title'>Corporate</div>");
include("content_corporate.php");
break;

case "business": 
echo("<div class='title'>Business</div>");
include("content_business.php"); 
break;

case "gallery":
echo("<div class='title'>Gallery</div>"); 
include("content_gallery.php"); 
break; 

case "weddings":
echo("<div class='title'>Wedding Car Service</div>");
include("content_weddings.php");
break;

case "contact":
echo("<div class='title'>Contact Us</div>");
include("content_contact.php");
break;

case "contactform":
echo("<div class='title'>Contact Form</div>");
include("content_contactform.php");
break;

case "sent":
echo("<div class='title'>Message Sent</div>");
include("content_sent.php");
break;

default: 
echo("<div class='title'>Home</div>");
include("content_home.php");
}
?>

switch ($x)

should be:

switch ($_GET['x'])

Also you dont need () for echos (although theres technically nothing wrong with using them.)

echo "something";

will suffice.

 

 

this sorted it, for some reason it worked on lycos though  ??? also for some reason putting echo $x wouldnt let the page load at all, even with the changes in this post :S

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.