I am having trouble trying to update my comment, well I also don't know why my table isn't displaying on my updatecomment.php page. How do you delete a comment too. If you see any other errors please feel free to fix it.
Thanks in advance
<!-- start dbconfig.inc.php page -->
<?php
$dbserver = '---';
$dbusername = '---';
$dbpassword = '---';
$dbdatabase = '---';
?>
<!-- end dbconfig.inc.php page -->
<!-- start dbconnect.inc.php page -->
<?php
require_once("dbconfig.inc.php");
$link = mysql_connect($dbserver, $dbusername, $dbpassword);
if (!$link) {
die('Could not connect to MySQL: ' . mysql_error());
}
mysql_select_db($dbdatabase, $link);
?>
<!-- end dbconnect.inc.php page -->
<!-- start dbdisconnect.inc.php page -->
<?php
mysqli: mysql_close($link);
?>
<!-- end dbdisconnect.inc.php page -->
<!-- start index.php page -->
<html>
<head>
<title>
My Guestbook - index page
</title>
</head>
<body>
<h1>My Guestbook</h1>
<h2>Recent Comments</h2>
<script type="text/javascript">
function update_me(obj) {
var selected_form = obj.form;
var id = selected_form.id.value;
selected_form.action = 'updatecomment.php';
selected_form.submit();
}
function delete_me(obj) {
var selected_form = obj.form;
var id = selected_form.id.value;
selected_form.action = 'deletecomment.php';
selected_form.submit();
}
</script>
<?php
date_default_timezone_set('America/New_York');
$today = date("Y-n-j H:i:s");
require('dbconnect.inc.php');
$entriesq = mysql_query("SELECT body, author_name FROM `Posts` LIMIT 0, 10 ") or die(mysql_error());
while($entriesr = mysql_fetch_array($entriesq)){
$author_name = $entriesr["author_name"];
$post_body = $entriesr["body"];
echo '<form method="post" >';
echo '<table>';
echo '<tr>';
echo '<td>';
echo '<input type="hidden" name="id" value="$id" />';
echo '<input type="button" name="Update" onClick="update_me(this)" value="Update" />';
echo '<input type="button" name="Delete" onClick="delete_me(this)" value="Delete" />';
echo " On $today $author_name said: $post_body";
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</form>';
}
require('dbdisconnect.inc.php');
?>
<br>
<a href="addcomment.php">Add a comment</a>
</body>
</html>
<!--end index.php page -->
<!-- start addcomment.php page -->
<html>
<head>
<title>
My Guestbook - Add Comment
</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
$body = $_POST['post_body'];
$author_name = $_POST['author_name'];
require('dbconnect.inc.php');
$body = mysql_real_escape_string(htmlspecialchars($_POST['post_body']));
$author_name = mysql_real_escape_string(htmlspecialchars($_POST['author_name']));
$sql = "INSERT INTO `Posts` (id,body,post_date,author_name) VALUES ('', '$body', '', '$author_name')";
$result = mysql_query($sql);
require('dbdisconnect.inc.php');
}
?>
<h1>Add a New Comment</h1>
<form action="addcomment.php" method="post">
<table>
<tr>
<td>
Name:
</td>
<td>
<input type="text" name="author_name" value="">
</td>
</tr>
<tr>
<td>
Message:
</td>
<td>
<textarea name="post_body">