Her er min kode: Den fil jeg includer i starten, er bare database-oplysningerne til phpmyadmin.
#Stefan: Netbeans mente at jeg skulle rette = til ===, hvilket jeg gjorde. Men burde den kunne finde ud af det, som han gør i videoen?
EDIT!!!!: Jeg ændrede det lige til = (dumt af mig, IKKE lige at gøre inden jeg postede) - Tak for svaret Stefan. Det virkede! Jeg vender tilbage hvis jeg har yderligere problemer. /Jeppe
<?php
if(!isset($_GET['id'])){
header('Location: index.php');
exit();
}else{
$id = $_GET['id'];
}
include 'includes/db_connect.php';
if(!is_numeric($id)){
header('Location: index.php');
}
$sql = "SELECT title, body FROM posts WHERE post_id='$id'";
$query = $db->query($sql);
if($query->num_rows !=1){
header('Location: index.php');
exit();
}
if(isset($_POST['submit'])){
$email = $_POST['email'];
$name = $_POST['name'];
$comment = $_POST['comment'];
if($email && $name && $comment){
$email = $db->real_escape_string($email);
$name = $db->real_escape_string($name);
$id = $db->real_escape_string($id);
$comment = $db->real_escape_string($comment);
if($addcomment === $db->prepare("INSERT INTO comments(post_id, name, email_add, comment) VALUES (?,?,?,?)")){
$addcomment->bind_param('ssss', $id, $name, $email, $comment);
$addcomment->execute();
echo "Thank you comment was added";
}else{
echo "Error";
}
}else{
echo "ERROR";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<style>
#container {
width: 800px;
padding: 5px;
margin: auto;
}
label {
display: block;
}
</style>
</head>
<body>
<div id="container">
<div id="post">
<?php
$row = $query->fetch_object();
echo "<h2>".$row->title."</h2>";
echo "<p>".$row->body."</p>";
?>
</div>
<hr />
<div id="add-comments">
<form action="<?php echo $_SERVER ['PHP_SELF']."?id=$id"?>" method="post">
<div>
<label>Email Adress</label><input type="text" name="email">
</div>
<div>
<label>Name</label><input type="text" name="name">
</div>
<div>
<label>Comment</label><textarea name="comment"></textarea>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
Indlæg senest redigeret d. 03.11.2012 21:19 af Bruger #17431