Jump to content

Query string question


BrianM

Recommended Posts

How is it that you get one page, say index.php, to contain content for multiple pages. Like - index.php?mode=register or index.php?mode=edit ... that being an example, I hope somebody see's what I'm getting at here. But how does a page use $_GET[''] based on the contents of the query string to determine what part of a page to display if it's all on one page?

Link to comment
https://forums.phpfreaks.com/topic/109695-query-string-question/
Share on other sites

when you use $_GET['variablename']  it retrieves the value for you from the URL.

so as in your example: the URL = index.php?mode=register


$a = $_GET['mode'];
//print($a);

 

Now you use that variable in a switch statement and use it to call your includes.

 

switch $a {

   case "register":
   include('register.php');
   break;
   
   case "edit":
   include('edit.php');
   break;
   
   case default:
   include('main.php');
   break;
   
}

 

you would setup all these pages to be the content of your site.

and put the above code at the top of your page.

 

Instead of making a new topic I thought I would continue in this one.

 

I'm getting this error with the following code, and I don't see any problem with it, hopefully somebody else will.

 

Error: Parse error: parse error, expecting `'('' in C:\Program Files\Apache Group\Apache2\htdocs\timetech\install.php on line 110

 

Code:

<?php
mysql_close($mysql_connect) or die(mysql_error());
} else if { // this is line 110
	header("Location: install.php?mode=delete");
	}
?>

yeah you can do that, just recall the page and change your variables witin the url. if you want to keep the same function for all of your pages.

 

i have some other examples of this floating around. but its 3:30am here now and i can't think straight anymore.

 

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.