Reply to Re: Approving Items

Your name:

Reply:


Posted by James54321 on 10/23/06 10:50

Drat, I tried to make the code work but it still does nothing after
clickig the "Go" button.

Heres what I have made so far and I cant personally see any problems
with it (but then again I have never done a foreach statement on
posts).

<?php
include('../config.php');
include('../head.php');
echo("<body bgcolor=\"lightblue\">");
echo("<title>approval</title>");
include('links.php');

function displayIdeas($result)
{

echo("<form method=\"post\">");

print "\n<table border=\"1\">\n<tr>\n" .
"\n\t<th>Approve</th>" .
"\n\t<th>Delete</th>" .
"\n\t<th>Ban</th>" .
"\n\t<th>Idea ID</th>" .
"\n\t<th>Idea Name</th>" .
"\n\t<th>Category</th>" .
"\n\t<th>Idea</th>" .
"\n\t<th>Time Submitted</th>" .
"\n\t<th>Date Submitted</th>" .
"\n\t<th>User</th>" .
"\n\t<th>IP Address</th>" .
"\n</tr>";

while($row = mysql_fetch_row($result)) {
list($ID,$Idea_Name,$Category,$Idea,$Time,$Date,$User,$IP_Address) =
$row;
{

if ($rowcounter == '1') {

print "\n<tr bgcolor=\"yellow\">";

$rowcounter = '2';
} else {

print "\n<tr bgcolor=\"lightblue\">";

$rowcounter = '1';
}

print "\n\t<td><center><input type=\"radio\" name=\"id[$ID]\"
value=\"Approve\" /></center></td>";

print "\n\t<td><center><input type=\"radio\" name=\"id[$ID]\"
value=\"Delete\" /></center></td>";

print "\n\t<td><center><input type=\"radio\" name=\"id[$ID]\"
value=\"Ban\" /></center></td>";


foreach($row as $data)

print "\n\t<td> {$data} </td>";

print "\n</tr>";

}
}

print "\n</table>\n";
echo("<input type=\"submit\" name=\"submit\"
value=\"Go\"></td></form>");
}

$query = "SELECT ID,Idea_Name,Category,Idea,Time,Date,User,IP_Address
FROM ideas WHERE Approved = 0 AND Category != 'ADMIN' Order by 'id'
ASC";

if (!($conn = @ mysql_connect($host,$user,$pass)))
die("Cannot Connect");

if (!(mysql_select_db($db,$conn)))
showerror();

if(!($result = @ mysql_query ($query)))
showerror();

displayIdeas($result);

mysql_close($conn);

if (isset($_POST['submit'])) {

//this is where the code i need should go :)

foreach ($_POST['id'] as $key => $value) {
switch ($value) {
case "Approve":
submission_approve($key); break;
case "Delete":
submission_delete($key); break;
case "Ban":
submission_ban($key); break;
default:
break;
}
}

//Well, that `submission_delete_or_whatever_it_was` is a function that
deletes (or something else) the submission of the id $key.

function submission_approve($id) {
$validated_id = $id;
// if ($validated_id < 1) return false;
echo("approved");
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$query = "INSERT INTO temp (ID, type) VALUES
('$validated_id','approved')";

//replace sites with your table name
//replace address and description with the filed name

// execute query
$result = mysql_query($query) or die ("Error in query: $query.
".mysql_error());

// print message with ID of inserted record
echo "New record inserted at now it will now go to the approvers";

// close connection
mysql_close($connection);

}


function submission_delete($id) {
$validated_id = (int)$id;
// if ($validated_id < 1) return false;

// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$query = "INSERT INTO temp (ID, type) VALUES
('$validated_id','deleted')";

//replace sites with your table name
//replace address and description with the filed name

// execute query
$result = mysql_query($query) or die ("Error in query: $query.
".mysql_error());

// print message with ID of inserted record
echo "New record inserted at now it will now go to the approvers";

// close connection
mysql_close($connection);
}


function submission_ban($id) {
$validated_id = (int)$id;
if ($validated_id < 1) return false;

// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$query = "INSERT INTO temp (ID, type) VALUES
('$validated_id','banned')";

//replace sites with your table name
//replace address and description with the filed name

// execute query
$result = mysql_query($query) or die ("Error in query: $query.
".mysql_error());

// print message with ID of inserted record
echo "New record inserted at now it will now go to the approvers";

// close connection
mysql_close($connection);

}



}

//close connection
mysql_close($conn);
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация