soccerstar22003 Posted June 26, 2006 Share Posted June 26, 2006 [code]<?if (!isset($_GET['page'])) { include ("home.html");} else { <-------- Line 36 if ($_GET['page'] != (home|contracts|reminders|accessories|contactus) { include ("home.html"); } else { $page = $_GET['page']; include ("/content/".$page.".html"); }}?> [/code]to me that looks fine, but when i test it, it comes up and says "Parse error: syntax error, unexpected '}' in C:\website\index.php on line 36" [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] i marked line 36 in the codeany help appreciated Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/ Share on other sites More sharing options...
dptr1988 Posted June 26, 2006 Share Posted June 26, 2006 You forgot to close the expression bracket in the second if statment.The code should be this:[code]<?if (!isset($_GET['page'])) { include ("home.html");} else { <-------- Line 36 if ($_GET['page'] != (home|contracts|reminders|accessories|contactus) ) { include ("home.html"); } else { $page = $_GET['page']; include ("/content/".$page.".html"); }}?> [/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49856 Share on other sites More sharing options...
redarrow Posted June 26, 2006 Share Posted June 26, 2006 try this ok[code]<?if (!isset($_GET['page'])) { include ("home.html");} elseif ($_GET['page'] != (home|contracts|reminders|accessories|contactus) { include ("home.html"); } else { $page = $_GET['page']; include ("/content/".$page.".html");}?> [/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49857 Share on other sites More sharing options...
soccerstar22003 Posted June 26, 2006 Author Share Posted June 26, 2006 thanks for the help, the code works now. i also have one other question. right now i am passing variable in the URL using /index.php?page=home but i have seen people use /index.php?home if i use the second script, how do i retrieve the variable home. Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49862 Share on other sites More sharing options...
dptr1988 Posted June 26, 2006 Share Posted June 26, 2006 I don't know if I have this right, but I will try to explain as I understand it.If you use /index.php?home you setting the $_GET['home'] variable to NULL. If you use /index.php?page=home your are setting the $_GET['page'] variable to 'home'. I would say the /index.php?page=home is better, but If you want to use the /index.php?home method, try this:[code]if ( isset($_GET['home']) | isset($_GET['contracts']) | .... isset($_GET['contactus']) ){include ("home.html");}else{ // the rest of your code....}[/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49873 Share on other sites More sharing options...
soccerstar22003 Posted June 27, 2006 Author Share Posted June 27, 2006 i redesigned the code to use the index.php?home format and this is what i came up with[code]<? if (!isset($_GET)) { include ("home.html");} elseif (isset($_GET['home'])) { <--------Line 37 include ("home.html");} elseif (isset($_GET['contracts'])) { include ("contracts.html");} elseif (isset($_GET['reminders'])) { include ("reminders.html");} elseif (isset($_GET['accessories'])) { include ("accessories.html");} elseif (isset($_GET['contactus'])) { include ("contactus.html");} else { include ("home.html");}?>[/code]it looks good to me but now i got a new issue, the error is almost the same: "Parse error: syntax error, unexpected '{' in C:\Inetpub\PMPOOLS\index.php on line 37"its as if it is not accepting the elseif statement isn't there so it is not expecting the condition that follows it. any reasons why it would do that? Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49918 Share on other sites More sharing options...
redarrow Posted June 27, 2006 Share Posted June 27, 2006 [code]<? if (! isset($_GET)) { include ("home.html");} elseif (isset($_GET['home'])) { include ("home.html");} else { $_GET['contracts']; include ("contracts.html");} elseif (isset($_GET['reminders'])) { include ("reminders.html");} else { $_GET['accessories']; include ("accessories.html");} elseif (isset($_GET['contactus'])) { include ("contactus.html");} else { include ("home.html");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49930 Share on other sites More sharing options...
soccerstar22003 Posted June 27, 2006 Author Share Posted June 27, 2006 i tried that and i got the same problem. Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49933 Share on other sites More sharing options...
redarrow Posted June 27, 2006 Share Posted June 27, 2006 Try this way or your have to alter it to the first old way ok.[code]<? if (! isset($_GET)) { include ("home.html");} elseif (! isset($_GET['home'])) { include ("home.html");} else { $_GET['contracts']; include ("contracts.html");} elseif (! isset($_GET['reminders'])) { include ("reminders.html");} else { $_GET['accessories']; include ("accessories.html");} elseif (! isset ($_GET['contactus'])) { include ("contactus.html");} else { include ("home.html");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49936 Share on other sites More sharing options...
trq Posted June 27, 2006 Share Posted June 27, 2006 What the?You cannot mix elseif, else elseif else. Its...[code]if () { } elseif () { } elseif () { } else {}[/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-49951 Share on other sites More sharing options...
wildteen88 Posted June 27, 2006 Share Posted June 27, 2006 Whats a mess! redarrow I suggest your go back to the manual and readup on if/elseif/else statements!As this:} else { $_GET['accessories'];does nothing!Also soccerstar22003 you might be better of with a switch statment instead:[code]<?php// check that p is set in the URLif (isset($_GET['p'])){ // now we include the correct page switch($_GET['p']) { case 'home': include 'home.html'; break; case 'contacts': include 'contacts.html'; break; case 'reminders': include 'reminders.html'; break; case 'accessories': include 'accessories.html'; break; case 'contactus': include 'contactus.html'; break; default: include 'home.html'; break; }}?><a href="?p=home">Home</a> | <a href="?p=contacts">Contacts</a> | <a href="?p=reminders">Reminders</a> | <br /><a href="?p=accessories">Accessories</a> | <a href="?p=contactus">Contact Us</a> | <a href="?p=contactus">Contact Us</a>[/code] Link to comment https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/#findComment-50010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.