Henter /Poster ikke Nyheds ID
HejsaJeg er i gang at lave et nyhes script som bruger en MySQL database
Jeg har disse 2 tabeller i min MySQL database:
Tabellen News:
CREATE TABLE `news` (
`id` int(11) NOT NULL auto_increment,
`emne` varchar(255) NOT NULL default '',
`nyhed` text NOT NULL,
`dato` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
)
og
Tabellen Comment:
CREATE TABLE `comment` (
`id` int(11) NOT NULL auto_increment,
`nyhedsid` int(11) NOT NULL default '0',
`navn` varchar(20) NOT NULL default '',
`email` varchar(30) NOT NULL default '',
`www` varchar(50) NOT NULL default '',
`kommentar` text NOT NULL,
`dato` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
)
Så har jeg en fil som hedder comment.php som ser sådan her ud:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Nyt dokument</title>
<meta name="generator" content="TSW WebCoder">
</head>
<body>
<?
include "mysql.php";
$query = mysql_query ("SELECT id, emne, dato, nyhed FROM news WHERE id = '$_GET[id]'") or die(mysql_error());
while ($newsrow = mysql_fetch_array($query)){
echo "
<table>
<tr>
<td>
<b>".$newsrow['emne']." - Dato: ".$newsrow['dato']."</b><br />
";
$text = htmlspecialchars($newsrow['nyhed']);
$text = str_replace(":D", "<img src=\"smilie/icon_biggrin.gif\">", $text);
$text = str_replace(":S", "<img src=\"smilie/icon_confused.gif\">", $text);
$text = str_replace(":8", "<img src=\"smilie/icon_cool.gif\">", $text);
$text = str_replace(":cr", "<img src=\"smilie/icon_cry.gif\">", $text);
$text = str_replace(":¨", "<img src=\"smilie/icon_eek.gif\">", $text);
$text = str_replace(":e", "<img src=\"smilie/icon_evil.gif\">", $text);
$text = str_replace("!", "<img src=\"smilie/icon_exclaim.gif\">", $text);
$text = str_replace(":i", "<img src=\"smilie/icon_idea.gif\">", $text);
$text = str_replace(":l", "<img src=\"smilie/icon_lol.gif\">", $text);
$text = str_replace(":[", "<img src=\"smilie/icon_mad.gif\">", $text);
$text = str_replace(":|", "<img src=\"smilie/icon_neutral.gif\">", $text);
$text = str_replace("?", "<img src=\"smilie/icon_question.gif\">", $text);
$text = str_replace(":r", "<img src=\"smilie/icon_razz.gif\">", $text);
$text = str_replace(":f", "<img src=\"smilie/icon_redface.gif\">", $text);
$text = str_replace(":re", "<img src=\"smilie/icon_rolleyes.gif\">", $text);
$text = str_replace(":(", "<img src=\"smilie/icon_sad.gif\">", $text);
$text = str_replace(":)", "<img src=\"smilie/icon_smile.gif\">", $text);
$text = str_replace(":O", "<img src=\"smilie/icon_surprised.gif\">", $text);
$text = str_replace(":tw", "<img src=\"smilie/icon_twisted.gif\">", $text);
$text = str_replace(";)", "<img src=\"smilie/icon_wink.gif\">", $text);
$text = nl2br($text);
echo $text;
?>
<br>
<br>
<?
echo "
<td>
</tr>
</table>
<br>
<hr />
";
}
?>
<br>
<br>
<?
include "mysql.php";
$query = mysql_query ("SELECT navn, email, www, kommentar FROM comment WHERE nyhedsid='$_GET[id]' ORDER BY id DESC") or die(mysql_error());
while ($rs = mysql_fetch_array($query)){
?>
<hr size="1" color="#000000" width="350">
<br />
<font size="1"><? echo $rs[dato] ?></font>
Navn: <? echo $rs[navn] ?>
<br>
<? echo "Netfang: <A HREF=\"mailto:$rs[email]\">$rs[email]</A>"; ?>
<br>
<? echo "WWW: <a href=\"$rs[www]\" target=\"_Blank\">$rs[www]</a>"; ?>
<br>
Skoðun: <? echo $rs[kommentar] ?>
<?
}
?>
<br>
<form action="post.php" method="post">
<table width="246" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="56" scope="col">Navn</th>
<th width="190" scope="col"><input type="text" name="navn"></th>
</tr>
<tr>
<th scope="row">Netfang</th>
<td><input type="text" name="email"></td>
</tr>
<tr>
<th scope="row">WWW</th>
<td><input type="text" name="www"></td>
</tr>
<tr>
<th scope="row">Skoðun</th>
<td><textarea name="kommentar"></textarea></td>
<input type="hidden" name="nyhedsid" value="<?php echo $rs[id]; ?>">
<input type="submit" name="Submit" value="Staðfesta">
</tr>
</table>
</form>
</body>
</html>
Nu kommer mit spørgsmål :
Når jeg skriver en Kommentar er jo meningen at Nyhedsid skal være det samme som id i Tabellen News
Men desværre bliver det ikke som jeg vil :(
Er der nogen som kan se fejl i mit script??
M.v.H. Th1
