<?php
include("config.php");
// Connect to server and select database.
$id=$_GET['id'];
$action=$_GET['action'];
if (!
isset($_SESSION['admin']))
if ($action == 'edit') {
$sql="SELECT * FROM $gb_tbl_name WHERE id=$id";
?>
<form name="edit" method="post" action="addguestbook.php?action=edit2">
Id: <input type="text" name="id" value="<? echo $rows['id']; ?>" /><br />
Name: <input type="text" name="name" value="<? echo $rows['name']; ?>" /><br />
Email: <input type="text" name="email" value="<? echo $rows['email']; ?>" /><br />
Comment: <textarea name=
"comment"><?
echo $rows['comment']; ?></textarea> <br />
Edit: <input type="radio" name="edit" value="name">Name
<input type="radio" name="edit" value="email">Email
<input type="radio" name="edit" value="comment">Comment <br />
<input type="submit" name="submit" value="Edit!">
</form>
<?
}
}
elseif ($action == 'edit2') {
$id=$_POST['id'];
$field=$_POST['edit'];
if ($field='name')
elseif ($field='email')
else
$sql="UPDATE $gb_tbl_name SET $field = $new_value WHERE `id` = $id";
header('Location: viewguestbook.php');
}
elseif ($action == 'delete') {
$sql="DELETE FROM $gb_tbl_name WHERE id=$id";
header('Location: viewguestbook.php');
}
elseif ($_POST['name'] != NULL || $_POST['comment'] != NULL) {
$datetime=
date("d-m-y h:i");
$sql="INSERT INTO $gb_tbl_name (name, email, comment, datetime) VALUES ('$name', '$email', '$comment', '$datetime')";
header('Location: viewguestbook.php');
}
echo "You must be logged in as an admin to delete / edit";
else
echo "You have to fill in your Name and Comment";
?>