Hello,
Getting back into web development, I'm finding myself quire removed from what I once remember. I"ve recently updated the PHP/MySQL association coding with mysqli instead of mysql as I see that is a way things are heading.
In a nut shell, I'm going through Lynda.com training videos on PHP, but I'm working on a mock website on the side, where I'm trying to put a fully functioning site together. I've done it before, but for the life of me my memory is not what it used to be.
This "mock site" is a gaming team website (helps keep interest, I enjoy gaming). I'm looking to make the site off 5 primary pages:
index
about
matches
roster
news
From there, I want to create the pages dynamically (eg. roster.php?id=10) and it would display content for whomever id 10 is in the roster table. Easy stuff, I thought.
I've looked into using switch statements to do this, but I cannot get the $_GET['id'] to read in the coding, so the URL will pull the proper content. My structure looks like this:
<?php
$id = $_GET['id'];
switch ($id)
{
case 1:
echo "ID 1";
break;
case 2:
echo "ID 2";
break;
default:
echo "No ID Selected";
}
?>
There is no MySQL here yet, as I'm trying to create a base to build off (I'm testing this by going to index.php?id=1 for example), and that's where it's not displaying properly.When visiting index.php?id=1 & ?id=2, the proper content shows. When I enter something like $id=3, it says No ID Selected, great! But when I go just to index.php, I receive the following error:
Notice: Undefined index: id in /home/user/public_html/index.php on line 23
No ID Selected
Line 23 is
$id = $_GET['id'];
Is this a syntax problem, where I've just coded this wrong, or a PHP.ini issue? I'm trying to nail this down before I start inputing the MySQL details and pull from my database.
Thank you for the guidance,
Jon
Aspiring Web Developer
@JonEdney1