Hello, I am stumped on a problem im having, and I get the feeling that the solution is quite simple yet requires knowledge of certain functions. Basically I am creating a guestbook which allows users to post comments, however I am trying to create an admin approval system so that comments must be approved before they can be seen.
So far I have an admin login system working and the entire guestbook system working, Users can post to the guestbook and I have created a table for these posts to be stored in, this table has an approved field. In my output pages I have an sql query which only displays rows which have approved set to 1.
I have also created a table for admin which allows them to log in to view the approve post page, this page currently shows all the posts which have approved set to 0. Currently I am making a table which dynamically changes in size as it adds a row for each post. There are two columns, one which contains the post and one which contains a checkbox. This table is part of a form and the idea is that the admin can select approve or deny which will then go back to more code to allow a sql function to find the post id and approve or deny as appropriate. My problem is that I don’t quite know how to link each checkbox to the form. Each of the comments in the sql table has a unique id, perhaps I can somehow use this?
Here is the code, I have commented out the login system but please let me know if there are better safer ways of doing things:
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Post Approval Area</title>
</head>
<body>
<?php
//if(!$userid && !$username){
//echo '<META HTTP-EQUIV="Refresh" Content="0; URL=./login.php">';
//exit;
}
?>
<?php
//////////////////////////connect to db area
mysql_connect("localhost", "x", "y");
mysql_select_db("z");// select database
?>
<?php
//////////////////////////if form pressed area
if($_POST['approvebtn']){
// this area will have a sql query which approves the posts as appropriate, I am simply struggling to know how to point the form elements from the table below into this.
}
?>
<form action='./approve4.php' method='post'>
<table width="500" border="1">
<?php
///////////////////// display form area
$query = mysql_query("SELECT * FROM guestbook WHERE Approve = '0' ORDER BY id DESC");
$numrows = mysql_num_rows($query);
while($row = mysql_fetch_assoc($query))//fetch assoc gets all info outta row
{
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$time = $row['time'];
$date = $row['date'];
$ip = $row['ip'];
$starsystem = $row['starsystem']; // will value pass thru?
$message = nl2br($message);
echo "
<tr>
<td><div>
By <b>$name</b> at <b>$time</b> on <b>$date</b><br />
Rating - <b>$starsystem</b> <br />
$message
</div>
</td>
<td>
<form id='form1' name='approve' form action='./guestbookinput.php' method='post'>
<p>
<label>
<input type='radio' name='approve' value='1' />
approve</label>
<br />
<label>
<input type='radio' name='approve' value='2' />
deny</label>
<br />
</p>
</form>
</td>
</tr>";
}
?>
<tr>
<td></td>
<td><input type='submit' name='approvebtn' value='Approve' /></td>
</tr>
</table>
</form>
</body>
</html>