Dateien anzeigen mit ?id=

hiho

ich habe gerade versucht, mit php anzufangen, und habe nun eine Frage:
ich möchte einen link eingeben, der z.b. /index.php?id=1 heißt und dann zur Datei test.php linkt, wenn ich jedoch den link /index.php?id=2 aufrufe, soll der Link zur Datei forum.html gehen.
wie mach ich das?

vllt hat jemand einen link zu einem tutorial zu genau dieser Frage?



cu
 
abend,

PHP:
if($id == "1") {
include("test.php");
}
elseif($id == "2") {
include("forum.html");
}
etc.

Ich hoffe, ich konnte helfen.

mfg
stephan
 
so sieht meine index.php aus:



<body>

<?php
if($id == "1") {
include("vorlage.php");
}
elseif($id == "2") {
include("forum.html");
}
?>

...
...

</body>

aber wenn ich das ausführe mit php, dann kommen 2 fehler, in denen die if und elseif als undefiniert angegeben werden...
 
Notice: Undefined variable: id in C:\Programme\HTTPd\htdocs\index.php on line 43

Notice: Undefined variable: id in C:\Programme\HTTPd\htdocs\index.php on line 46


zeile 43:
if($id == "1") {

zeile 46:
elseif($id == "2") {


das ganze komplett:
<?
if($id == "1") {
include("vorlage.php");
}
elseif($id == "2") {
include("forum.html");
}
?>
 
wenns interessiert poste ich mal die ganze index.php:






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
}
body {
background-color: #e1e1e8;
}
a:link {
color: #0D0880;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #0D0880;
}
a:hover {
text-decoration: none;
color: #980D12;
}
a:active {
text-decoration: none;
color: #0D0880;
}
a {
font-size: 12px;
}
-->
</style>
</head>

<body>

<?
if($id == "1") {
include("vorlage.php");
}
elseif($id == "2") {
include("forum.html");
}
?>

<table width="907" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="86">&nbsp;</td>
<td width="817"><img src="blue.jpg" width="350" height="65"></td>
</tr>
</table>
<table width="907" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="86">&nbsp;</td>
<td width="817"><table width="768" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="3"></td>
</tr>
<tr>
<td><table width="768" cellspacing="0" cellpadding="0" style="border:1px solid #0D0880">
<tr>
<td><table width="767" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="136" valign="top"><table width="136" height="21" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="3"></td>
<td width="110" height="3"></td>
<td width="3"></td>
</tr>
<tr>
<td height="15">&nbsp;</td>
<td><table width="130" border="0" cellspacing="1" cellpadding="0">
<tr>
<td bgcolor="#0D0880">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#0D0880">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table></td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="3"></td>
<td width="110" height="3"></td>
<td width="3"></td>
</tr>
</table></td>
<td width="631" align="left" valign="top"><table width="632" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="632" height="3"></td>
</tr>
<tr>
<td><table width="679" cellspacing="0" cellpadding="0" style="border-left:1px solid #0D0880">
<tr>
<td width="669"><table width="678" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="3"></td>
<td width="659">Diese Seite dient als Vorlage, hier kommt der Inhalt rein <br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br></td>
</tr>
</table> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="3"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
 
also, bei mir gehts problemlos. auch, wenn ich $id vorhher nicht definiere.
versuch mal, $id = ""; ganz am anfang einzufügen und versuchs nochmal.

mfg
 
hmm, ja, jetzt geht es, lag wohl an meinem php-server...

aber was anderes:

wenn ich index.php aufrufe, dann kommt ganz normal die seite index.php, die ja den html-text enthält.
wenn ich aber index.php?id=1 aufrufe, dann öffnet er die index.php und gleich darunter die vorlage.php ...

weiß da jemand abhilfe?



cu
 
Zeig mal den Code der vorlage.php. Der darf natürlich nicht mit <html><head>... anfangen, sonden sollte lediglich Code und evtl. Formatierungstags enthalten.
 
ist derselbe code wie bei der index.php, außer dass eben "" an der einen stelle steht, und nicht "Hier kommt der Inhalt rein"





vorlage.php






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
}
body {
background-color: #e1e1e8;
}
a:link {
color: #0D0880;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #0D0880;
}
a:hover {
text-decoration: none;
color: #980D12;
}
a:active {
text-decoration: none;
color: #0D0880;
}
a {
font-size: 12px;
}
-->
</style>
</head>

<body>
<table width="907" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="86">&nbsp;</td>
<td width="817"><img src="blue.jpg" width="350" height="65"></td>
</tr>
</table>
<table width="907" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="86">&nbsp;</td>
<td width="817"><table width="768" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="3"></td>
</tr>
<tr>
<td><table width="768" cellspacing="0" cellpadding="0" style="border:1px solid #0D0880">
<tr>
<td><table width="767" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="136" valign="top"><table width="136" height="21" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="3"></td>
<td width="110" height="3"></td>
<td width="3"></td>
</tr>
<tr>
<td height="15">&nbsp;</td>
<td><table width="130" border="0" cellspacing="1" cellpadding="0">
<tr>
<td bgcolor="#0D0880">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#0D0880">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table></td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="3"></td>
<td width="110" height="3"></td>
<td width="3"></td>
</tr>
</table></td>
<td width="631" align="left" valign="top"><table width="632" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="632" height="3"></td>
</tr>
<tr>
<td><table width="679" cellspacing="0" cellpadding="0" style="border-left:1px solid #0D0880">
<tr>
<td width="669"><table width="678" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="3"></td>
<td width="659"> :)<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br></td>
</tr>
</table> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="3"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
 
Zurück