Page 1 of 1
passing information from a browser
Posted: Mon Dec 21, 2009 2:50 pm
by michaelk46

I am rather confused on how this works...
I have setup a MySQL database that contains information for individual webpages. I also setup a PHP page to automatically create those webpages based on the pagename that is stored in the database.
The part that I do not understand is how the information necessary to create the pages is supposed to get from the browser to the PHP page so the correct webpage can be generated.
I hope that is clear enough to answer... If not I can clarify.
Thanks in advance
Re: passing information from a browser
Posted: Mon Dec 21, 2009 2:58 pm
by AbraCadaver
In many cases people opt for the following:
http://www.example.com/index.php?page=home
Then in index.php you can take the value of $_GET['page'] and use that.
Re: passing information from a browser
Posted: Mon Dec 21, 2009 3:11 pm
by michaelk46
Is that something that is passed automatically, or is there something that you have to setup before it works. The part that i am referring to is index.php?page=home. I understand how to use the get to read the information.
That might not be clear, but that's just how confused I am about this.
Re: passing information from a browser
Posted: Mon Dec 21, 2009 3:21 pm
by AbraCadaver
You would construct your links on the pages to look like that. Imagine you have a header on every page with links to 'About Us', 'Contact', 'Support', etc.. Then you would write the links like this:
Code: Select all
<a href="index.php?page=about_us">About Us</a>
etc...
Then in index.php any of the variables in the URL (get parameters) are availbale in the $_GET array. So you could do something like this (very simplified example):
Code: Select all
switch ($_GET['page']) {
case 'about_us':
//get page stuff from database and assign to var or vars, etc...
break;
//etc...
}
//echo your page
-- or --
Code: Select all
$query = "SELECT * from pages WHERE page_name = '" . mysql_real_escape_string($_GET['page']) . "'";
//echo or do stuff with results
Re: passing information from a browser
Posted: Mon Dec 21, 2009 3:24 pm
by Christopher
Moved to PHP Code.
Re: passing information from a browser
Posted: Mon Dec 21, 2009 3:33 pm
by michaelk46
So the name of every page would be index.php?page= and then whatever the actual page name is. Am i getting that correctly?
Re: passing information from a browser
Posted: Mon Dec 21, 2009 3:35 pm
by AbraCadaver
michaelk46 wrote:So the name of every page would be index.php?page= and then whatever the actual page name is. Am i getting that correctly?
Yes, it could be or it could be a number or whatever you have stored in the DB that you can query to get your page data.
Re: passing information from a browser
Posted: Mon Dec 21, 2009 4:21 pm
by michaelk46
Thanks for all your help...that's what I needed to know