Hej alle jeg har et lille problem
jeg har denne her kode som virker...
-------------------------------------------------
<?
$mysqli = new mysqli("localhost", "root", "******", "comment");
echo '<font size="4" color="green">Leave a comment:</font>';
?>
<form action="<?$_SERVER['PHP_SELF'];?>" method="post">
<p><input type="text" name="name" value="Anonymous" size="30" maxlength="30" /> <small>Name</small></p>
<p><input type="text" name="comment" size="30" maxlength="250" /> <small>Comment</small></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<table border=1><tr><td>
<?
$query = "SELECT * FROM comments ORDER BY id DESC LIMIT 5";
$result = $mysqli->query($query);
while($data = $result->fetch_array(MYSQLI_ASSOC)) {
echo "</td></tr><tr><td>";
echo "<small><br>".$data['date']." - <b>". $data['name']."</b>";
echo "<br>".htmlspecialchars($data['comment'])."</small><br>";
}
$name = $_POST['name'];
$name = strip_tags($name);
$comment = $_POST['comment'];
$comment = strip_tags($comment);
$date = date("r");
$ip = getenv("REMOTE_ADDR");
if (!empty($comment)) {
if (empty($name)) {
echo "<br><b>You didn't include a name.</b>";
}
if (empty($comment)) {
echo "<br><b>You forgot to type in a comment.</b>";
}
$query = "INSERT INTO comments (name, comment, date, ip) VALUES ('$name', '$comment', '$date', '$ip')";
$mysqli->query($query);
echo '<meta http-equiv="refresh" content="1" />';
}
$mysqli->close();
?>
-----------------------------------------------
Men når jeg så laver lidt om på den. ved at sætte en ekstra input ind så virker det ikke mere og jeg ved simpelthen ikke hvorfor...
Her er koden efter ændringen
-----------------------------------------------
<?
$mysqli = new mysqli("localhost", "user", "******", "comment");
echo '<font size="4" color="green">Leave a comment:</font>';
?>
<form action="<?$_SERVER['PHP_SELF'];?>" method="post">
<p><input type="text" name="name" value="Anonymous" size="30" maxlength="30" /> <small>Name</small></p>
<p><input type="text" name="comment" size="30" maxlength="250" /> <small>Comment</small></p>
<p><input type="text" name="mail" size="30" maxlength="250" /> <small>E-mail</small></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<table border=1><tr><td>
<?
$query = "SELECT * FROM comments ORDER BY id DESC LIMIT 5";
$result = $mysqli->query($query);
while($data = $result->fetch_array(MYSQLI_ASSOC)) {
echo "</td></tr><tr><td>";
echo "<small><br>".$data['date']." - <b>". $data['name']."</b>";
echo "<br>".htmlspecialchars($data['comments'])."</small><br>";
}
$name = $_POST['name'];
$name = strip_tags($name);
$comment = $_POST['comments'];
$comment = strip_tags($comments);
$mail = $_POST['mail'];
$mail = strip_tags($mail);
$date = date("r");
$ip = getenv("REMOTE_ADDR");
if (!empty($comment)) {
if (empty($name)) {
echo "<br><b>You didn't include a name.</b>";
}
if (empty($comment)) {
echo "<br><b>You forgot to type in a comment.</b>";
}
if (empty($mail)) {
echo "<br><b>You forgot to type in a mail.</b>";
}
$query = "INSERT INTO comments (name, comments, mail, date, ip) VALUES ('$name', '$comments', '$mail', '$date', '$ip')";
$mysqli->query($query);
echo '<meta http-equiv="refresh" content="1" />';
}
$mysqli->close();
?>
-----------------------------------------------
Håber nogle kan hjælpe mig :-)
Indlæg senest redigeret d. 25.06.2009 14:21 af Bruger #15115