Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.