Solved

Question For lozloz ONLY

Posted on 2003-12-01
5
230 Views
Last Modified: 2006-11-17
Hi again loz!

I have a script written in ASP that I use to display multiple pages of content with only one page....


http://www.mysite.com/index.asp?pg=home
http://www.mysite.com/index.asp?pg=terms

Here is the script I use:  <%ASP%>
<%
                                          action=Request.querystring("action")
      if action = "" then
                action = "home"
      end if

      Select Case action

                                                Case "home"
                                                      Server.Execute"content/home.asp"
                                                Case "services"
                                                      Server.Execute"content/home.asp"
                                                     Case "payments"
                                                      Server.Execute"content/home.asp"
                                                      Case "faq"
                                                      Server.Execute"content/home.asp"            
                        
Case else
End Select
%>

As I'm just beginning to learn PHP (and mind you it hasn't been as easy as I thought it would be) could you please give me a PHP example for converting this code?

Also, one other question I have is this....I reference all of my links by calling the value of the page I'm on (i.e., <a href="<%Request.ServerVariables("SCRIPT_NAME")%>?action=payments">).  The page the Request.ServerVariables will call is the index page.  Can you also give an example of that in PHP?

I hate to be soo much trouble, but I was very pleased with your help in my previous question.

Thanks in advance,

Trent
0
Comment
Question by:wkpreferredsolutions
[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
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9855269
hi there,

interesting what you say about php - i learnt php first and have found learning asp a lot harder than php.. maybe it's the 2nd language in the sequence which is harder. this should be quite easy to follow logically:

if(empty($_GET["action"])) { // if action = "" then
  $action = "home";
} else {
  $action = $_GET["action"]; // action=Request.querystring("action")
}
switch ($action){ // Select Case action
  case: "home"
    include("content/home.asp"); // Server.Execute"content/home.asp"
    break; // break is required otherwise all the cases below are executed as well unless another break is encountered
  case: "services"
    include("content/home.asp");
    break;
  case: "payments"
    include("content/home.asp");
    break;
  case: "faq"
    include("content/home.asp");
    break;
  // for a default case you want the following
  // default:
} // End Select

seems a bit strange wanting to include the same page for each action though so i assume you'll be changing this later

Request.ServerVariables in asp is equivalent to $_SERVER["SCRIPT_NAME"] but generally we use $_SERVER["PHP_SELF"] as this is a string containing the filename relative to the server's root

so for an example for your link - <?php print <a href=\"" . $_SERVER["PHP_SELF"] . "?action=payments\">Payments</a>"; ?>, or to be exact in the form of your code:

<a href="<? print $_SERVER["PHP_SELF"]; ?>"?action=payments">Payments</a>

good luck

loz
0
 

Author Comment

by:wkpreferredsolutions
ID: 9855694
Thanks for the quick reply loz!

I was always told that ASP was one of the harder languages to learn and PHP would be so much easier to learn after learning ASP!!!  I think I was lied to, :-)

The same include file was from a quick cut and paste in a script I was working on that I never finished.

I'm getting a parse error whenever the script reaches this line:

if(empty($_GET["action"])) { // if action = "" then
  $action = "home";
} else {
  $action = $_GET["action"]; // action=Request.querystring("action")
}
switch ($action){ // Select Case action
  case: "home" <=========================Parse Error On This Line

Trent
0
 
LVL 13

Accepted Solution

by:
lozloz earned 500 total points
ID: 9855729
sorry that's me being silly, all the cases should be in the following form:

case "home":

so:

switch ($action){ // Select Case action
  case "home" :
    include("content/home.asp"); // Server.Execute"content/home.asp"
    break; // break is required otherwise all the cases below are executed as well unless another break is encountered
  case "services":
    include("content/home.asp");
    break;
  case "payments":
    include("content/home.asp");
    break;
  case "faq":
    include("content/home.asp");
    break;
  // for a default case you want the following
  // default:
} // End Select

cheers,

loz
0
 

Author Comment

by:wkpreferredsolutions
ID: 9855734
Yep!  That fixed it!

Thanks again for the great answers!  Points are on the way!

Trent
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9855837
glad to help

loz
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 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