Hallo beste Tweakers,
Een klein probleempje heb ik hier.
Het gaat om het volgende; ik wil een commentbox op mijn website. Hij hoeft niet zo geavanceerd te zijn. Naam invoeren en bericht invoeren. Het script zelf heb ik al.
[code=php]<html>
<head>
<title>Comment</title>
</head>
<body>
<?php
$act = $_POST['act'];
if($act == "post") {
$name = $_POST['name'];
$message = $_POST ['message'];
@$fp = fopen("comments.php", 'a');
if (!$fp) {
//The file could not be opened
echo "There was an error! Please try again later!";
exit;
} else {
//The file was successfully opened, lets write the comment to it.
$outputstring = "<br>Name: " .$name. "<br> Comment:<br>" .$message. "<br>";
//Write to the file
fwrite($fp, $outputstring, strlen($outputstring));
//We are finished writing, close the file for security / memory management purposes
fclose($fp);
//Post the success message
echo "Your post was successfully entered. Click <a href='index.html'>here</a> to continue.";
}
} else {
//We are not trying to post a comment, show the form.
?>
<h2>Previous comments:</h2>
<?php include("comments.php"); ?>
<br><br>
<h2>Post a comment:</h2>
<form action="commentindex.php" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" value=""></input></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name="message"></textarea></td>
</tr>
</table>
<input type="hidden" name="act" value="post"></input>
<input type="submit" name="submit" value="Submit"></input>
</form>
<?php
}
?>
</body>
</html>
[/code=php]
Maar het probleem zit hier:
Ik heb namelijk het script in mijn html website geplakt. Hij werkt goed, op een ding na. De code
werkt niet. Het idee van deze code is dat de comments op de plek worden weergeven waar het aan is gegeven (tenminste daar ga ik van uit). Alle comments die worden getypt komen wel in de comment.php te staan. Alleen hij include hem niet op de website.
Werkt die code niet in combinatie met html? Of doe ik iets verkeerds?
Bedankt.
Een klein probleempje heb ik hier.
Het gaat om het volgende; ik wil een commentbox op mijn website. Hij hoeft niet zo geavanceerd te zijn. Naam invoeren en bericht invoeren. Het script zelf heb ik al.
[code=php]<html>
<head>
<title>Comment</title>
</head>
<body>
<?php
$act = $_POST['act'];
if($act == "post") {
$name = $_POST['name'];
$message = $_POST ['message'];
@$fp = fopen("comments.php", 'a');
if (!$fp) {
//The file could not be opened
echo "There was an error! Please try again later!";
exit;
} else {
//The file was successfully opened, lets write the comment to it.
$outputstring = "<br>Name: " .$name. "<br> Comment:<br>" .$message. "<br>";
//Write to the file
fwrite($fp, $outputstring, strlen($outputstring));
//We are finished writing, close the file for security / memory management purposes
fclose($fp);
//Post the success message
echo "Your post was successfully entered. Click <a href='index.html'>here</a> to continue.";
}
} else {
//We are not trying to post a comment, show the form.
?>
<h2>Previous comments:</h2>
<?php include("comments.php"); ?>
<br><br>
<h2>Post a comment:</h2>
<form action="commentindex.php" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" value=""></input></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name="message"></textarea></td>
</tr>
</table>
<input type="hidden" name="act" value="post"></input>
<input type="submit" name="submit" value="Submit"></input>
</form>
<?php
}
?>
</body>
</html>
[/code=php]
Maar het probleem zit hier:
code:
1
| <?php include("comments.php"); ?> |
Ik heb namelijk het script in mijn html website geplakt. Hij werkt goed, op een ding na. De code
code:
1
| <?php include("comments.php"); ?> |
werkt niet. Het idee van deze code is dat de comments op de plek worden weergeven waar het aan is gegeven (tenminste daar ga ik van uit). Alle comments die worden getypt komen wel in de comment.php te staan. Alleen hij include hem niet op de website.
Werkt die code niet in combinatie met html? Of doe ik iets verkeerds?
Bedankt.