Hi all,
New to this forum and PHP, but this looks like a great place to start
I've been typing along in my free time trying to create my own CMS (Content Management System) from scratch. Just wanting to start with something basic. I won't bore you with endless amounts of code, however, I'll just get right down to my current minor issue I have not been able to fix my self.
I've looked far and wide and can't seem to find an answer (I'm probably doing it wrong).
<html>
<head>
<title> Welcome to CJFS! </title>
</head>
<body>
<?php
include ("head.php");
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td valign="top" align="left" width="90">
<?php
include ("menu.php");
?>
</td>
<td width="1" valign="top"> </td>
<td valign="top">
<?php
$content = $_GET['con'];
if (($content) == NULL) {
include ('home.php');
}
else {
include ($content.'.php');
}
?>
</td>
<td width="1" bgcolor="#FFFFFF" valign="top"></td>
</tr></table>
</body></html>
That is my attempt at a home page. The index.php is split up into 3 cells (in a table), and a different page is called to each cell (head.php for the header, my logo or title or whatever, menu.php for my menu along the left, and then my PHP code for my main content / body section).
I basically want the index.php page to be static (meaning head.php and menu.php are always shown, and the content area is the only page that changes when a user clicks on a link) and this is what I've devised to do so from my minimal knowledge:
<?php
$content = $_GET['con'];
if (($content) == NULL) {
include ('home.php');
}
else {
include ($content.'.php');
}
?>
Now my menu.php links are set up to go to "index.php?con=example" where example is one of my other content pages (like contact, home, about, etc.). As far as I know (and it does work right now), I'm setting the $content variable to $GET the "con" result from the URL (so if the link wants index.php?con=contact, it will $GET "contact" and set "contact" as $content). From there, I've set if $content is null (meaning if a user tries to access just index.php without a ?con=example) it will load up the home.php page in the content section. Else (if $content contains a variable other than null) load up the page name followed by .php (so if the link was index.php?con=contact, the content section would load contact.php)
Did I forget to mention it works? It may not be the best way but it does! Now, my problem:
Notice: Undefined index: con in C:\webs\sites\cjfs.no-ip.org\site\htdocs\index.php on line 20
Line 20 being:
$content = $_GET['con'];
Now, I know you can turn off Notices in the php.ini, however I'd prefer not to do that (as I'm still learning and notices help!).
Can anyone suggest either
A: A way to change my code or script so that it does not show that notice (Hence the title of my post, I don't know but I figured if I could set the variable to null until it's needed it might eliminate that Notice, but I tried a bunch of different ways with no luck)
or
B: A better way to accomplish my original goal (having the header and menu stay while changing the content part depending on what link is clicked)?
I'm a college student and unfortunately they only want to teach us ASP in class, although frankly it's only that knowledge that's even gotten me this far
Any help would be appreciated