?
Solved

How do I pass parameters in PHP?

Posted on 2009-07-03
6
Medium Priority
?
307 Views
Last Modified: 2012-05-07
Hi there, I'm a newbie with php and not much of a programmer, I let Dreamweaver do most of the work. I am trying to pass parameters through the URL to load a page within a page for example
aboutus.php?pageid=1 sort of thing.
I have defined the recordset and want to load the content of the page with the corresponding id.
How do I do it?
0
Comment
Question by:cokefour
[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
6 Comments
 
LVL 11

Accepted Solution

by:
BrianMM earned 630 total points
ID: 24771358
OK something like;

if(isset($_REQUEST['pageid']) {
  // code to get the content for that page i.e. do your query with something like SELECT * from table WHERE id = $_REQUEST['pageid']
} else {
  // get some default content i.e. no pageid was passed...
}
0
 
LVL 5

Author Comment

by:cokefour
ID: 24771534
the '{' is throwing errors after [pageid]
0
 
LVL 28

Assisted Solution

by:gamebits
gamebits earned 60 total points
ID: 24771620
if(isset($_REQUEST['pageid']) {

should be

if(isset($_REQUEST['pageid'])) {  

was missing a bracket )
0
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
LVL 4

Assisted Solution

by:stevepicks
stevepicks earned 60 total points
ID: 24771661
try this also
<?php
$pageid= $_GET['pageid']; // or $_POST['pageid']; if u used a form to post variable
switch ($pageid) {
    case 1:
        echo "page = 1";
        break;
    case 2:
        echo "page = 2";
        break;
    default:
       echo "not a known page";
}
?>
0
 
LVL 11

Assisted Solution

by:BrianMM
BrianMM earned 630 total points
ID: 24771908
doh :) typing too quickly as usual :|
0
 
LVL 5

Author Closing Comment

by:cokefour
ID: 31599514
thanks guys
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 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