Click to See Complete Forum and Search --> : PHP Help
brainiac744
12-05-2003, 05:58 PM
I think this code should work, but it isn't!! When I attach the variable to the url (i.e. ministries.php?id=kids) I get the error.php file(from the else statement). Maybe I'm trying to add to the url incorrectly? Any help appreciated on improving code or fixing it. I'm very new at PHP.
<?php
$titlename="Ministries";
Include("header.php")
?>
<body>
<?php
Include("css_1.php")
?>
<?php
if ( $id == '' ) {
if ( $id == kids ) {
Include("kids.php");
}
if ( $id == teens ) {
Include("teens.php");
}
if ( $id == college ) {
Include("college.php");
}
if ( $id == singles ) {
Include("singles.php");
}
if ( $id == music ) {
Include("music.php");
}
if ( $id == drama ) {
Include("drama.php");
}
if ( $id == growth ) {
Include("growth.php");
}
if ( $id == tape ) {
Include("tape.php");
}
if ( $id == other ) {
Include("other.php");
}
if ( $id == involve ) {
Include("involve.php");
}
else {
Include("error.php");
}
}
else {
Include("min_body.php");
}
?>
<?php
Include("css_2.php");
Include("menu.php");
Include("footer.php");
?>
</body>
</html>
brainiac744
12-05-2003, 06:29 PM
Woops! I just saw a mistake! New code here:
<?php
$titlename="Ministries";
Include("header.php")
?>
<body>
<?php
Include("css_1.php")
?>
<?php
if ( isset($id) ) {
if ( $id == kids ) {
Include("kids.php");
}
if ( $id == teens ) {
Include("teens.php");
}
if ( $id == college ) {
Include("college.php");
}
if ( $id == singles ) {
Include("singles.php");
}
if ( $id == music ) {
Include("music.php");
}
if ( $id == drama ) {
Include("drama.php");
}
if ( $id == growth ) {
Include("growth.php");
}
if ( $id == tape ) {
Include("tape.php");
}
if ( $id == other ) {
Include("other.php");
}
if ( $id == involve ) {
Include("involve.php");
}
else {
Include("error.php");
}
}
else {
Include("min_body.php");
}
?>
<?php
Include("css_2.php");
Include("menu.php");
Include("footer.php");
?>
</body>
</html>
Now it always takes me to the min_body.php page!! GAHHHH It's Killing Me!
brainiac744
12-05-2003, 09:31 PM
OK, after much staring and some research, I finally found something that works! So, here it is:
<?php
$titlename="Ministries";
Include("header.php")
?>
<body>
<?php
Include("css_1.php");
?>
<?php
global $HTTP_GET_VARS;
if ( $HTTP_GET_VARS["id"] == kids ) {
Include("kids.php");
}
elseif ( $HTTP_GET_VARS["id"] == teens ) {
Include("teens.php");
}
elseif ( $HTTP_GET_VARS["id"] == college ) {
Include("college.php");
}
elseif ( $HTTP_GET_VARS["id"] == singles ) {
Include("singles.php");
}
elseif ( $HTTP_GET_VARS["id"] == music ) {
Include("music.php");
}
elseif ( $HTTP_GET_VARS["id"] == drama ) {
Include("drama.php");
}
elseif ( $HTTP_GET_VARS["id"] == growth ) {
Include("growth.php");
}
elseif ( $HTTP_GET_VARS["id"] == tape ) {
Include("tape.php");
}
elseif ( $HTTP_GET_VARS["id"] == other ) {
Include("other.php");
}
elseif ( $HTTP_GET_VARS["id"] == involve ) {
Include("involve.php");
}
else {
Include("min_body.php");
}
?>
<?php
Include("css_2.php");
Include("menu.php");
Include("footer.php");
?>
</body>
</html>
Read why: http://www.webdevfaqs.com/php.php#globalvariables
Hey pyro,
elseif ( $HTTP_GET_VARS["id"] == tape ) {
why wouldnt you need qoutes around tape?
It's in a get right? Like: something.php?id=tape
:confused:
Umm... you should. I'd be surprised if that works for you. With no quotes, PHP is going to assume that it is a constant, which I'm quite sure it is not.
chadypu
12-06-2003, 10:53 AM
to make the code a little less bulky without the get vars stuff in every line you could just do this with your original code...
<?php
$titlename="Ministries";
Include("header.php");
echo '<body>';
Include("css_1.php");
$id = $_GET['id'];
if ($id)
{
include $id.'php';
}
else
{
Include("min_body.php");
}
Include("css_2.php");
Include("menu.php");
Include("footer.php");
echo '</body></html>';
?>
you might wanna add in something that will read the included file and if its non existent include error
This (http://forums.webdeveloper.com/showthread.php?s=&threadid=22479) thread might help... we pretty much beat the topic to death there... ;)
Also, chadypu, you forgot a closing ' on line 6:
$id = $_GET['id];
chadypu
12-06-2003, 04:01 PM
oops, told you i suck at php :p
brainiac744
12-06-2003, 04:25 PM
Originally posted by pyro
Umm... you should. I'd be surprised if that works for you. With no quotes, PHP is going to assume that it is a constant, which I'm quite sure it is not.
It's not, but it does work...I'm going to go add quotes now anyway though.