[56K WARN] pages
Posted: Fri Mar 31, 2006 2:57 pm
i have created something that will allow staff members to put up content on my site.


this adds the guide to the site, but, we can not delete or edit the skill guide, why?
here is what happens when i click edit or delete

here is the php code
the mysql database
this adds the guide to the site, but, we can not delete or edit the skill guide, why?
here is what happens when i click edit or delete
here is the php code
Code: Select all
//------------------------Begin Skill-------------------------------------------//
function skill(){
$page = $_GET['page'];
if(empty($page)){
$page = 1;
}
$limit = 25;
$query_count = "SELECT id FROM skill";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$limitvalue = $page * $limit - ($limit);
echo '<p><center><font class="adminheader">SKill Admin</font></center></p>';
echo "<TABLE border=\"0\" width=\"89%\" class=monster>\n";
echo "<TR><TD class=title><center>Skill Name</center></td><td class=title><center>Edit</center></TD</TR>\n";
/* query for Skills */
$query = "SELECT id, name, sorter FROM skill ORDER BY sorter ASC LIMIT $limitvalue, $limit";
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc ($result)) {
/* display skills in a table */
$count = $count + 1;
/* place table row data in
* easier to use variables.
*/
$id = $row['id'];
$title = $row['name'];
/* display the data */
echo '<TR bgcolor="'.processRow($count).'"><TD class="calc"><b>'.$title.'</b></td><td class="calc"><a href="'.$_SERVER['PHP_SELF'] . '?flibble=update_s&id='.$row['id'].'"><img src="images/admin/view.gif" alt="Edit" border="0"></a> <a href="'.$_SERVER['PHP_SELF'] . '?flibble=delete_s&id='.$row['id'].'"><img src="images/admin/delete.gif" alt="Delete" border="0"></a></TD></TR>';
if($count == 2){
$count = 0;
}
}
/* finish up table*/
echo "</TABLE><center>\n";
if($page != 1){
$pageprev = $page-1;
echo '<a href="admin2.php?flibble=skill&page='.$pageprev.'">Previous</a> ';
}else{
echo 'Previous ';
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo $i.' ';
}else{
echo ' <a href="admin2.php?flibble=skill&page='.$i.'">'.$i.'</a> ';
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo $i.' ';
}else{
echo ' <a href="admin2.php?flibble=skill&page='.$i.'">'.$i.'</a> ';
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page+1;
echo ' <a href="admin2.php?flibble=skill&page='.$pagenext.'">Next</a>';
}else{
echo ' Next';
}
mysql_free_result($result);
echo '</center>';
echo '<p><b><a href="http://runehints.com/admin2.php?flibble=add_s"><img src="images/plus.gif" alt="Add" border="0"> Add a skill guide</a></b></p>';
}
function update_s($id) {
if (isset($_POST['preview'])){ //handle form
$name = $_POST['name'];
$contributors = $_POST['contributors'];
$guideby = $_POST['guideby'];
$members = $_POST['members'];
$guide = $_POST['guide'];
if ($members = "Y") {
$mem = "members only skill</b>, so it can only be done on a <b>members</b> server.";
}else{
$mem = "non-members skill</b>.";
}
if ($updated == 0){
$up = 'No-one has updated this skill guide';
}else{
$date2 = date("l jS of F Y @ H:i:s ", $updated);
$up = 'It was last updated on '.$date2.'.';
}
if ($contributors != ""){
$con = 'Thanks also to <b>'.$contributors.'</b> for changes.';
}else{
$con = 'No-one else has contributed to this skill guide';
}
//$date = date("D M jS, Y g:i a", $added);
$date = date("l jS of F Y @ H:i:s ", $added);
echo '
<p class="skillheader">'.$name.'</p>
<p>This skill guide was written by <b>'.$guideby.'</b> for use on Runehints. '.$con.' <br /></p>
<p class="small2"><br />This skill is <b>'.$mem.'</p>
<p>
<span class="titles">Skill Instructions:</span></p>
<div id="skill">
<p>
<?php echo $guide; ?>
</p></div>
<?php
echo '
;
}
if (isset($_POST['submit'])){ //handle form
require_once ('../mysql_connect.php');//connect to db
$name = $_POST['name'];
$guideby = $_POST['guideby'];
$members = $_POST['members'];
$guide = $_POST['guide'];
$contributors = $_POST['contributors'];
$updated = time();
$sorter = $_POST['sorter'];
if ($name){//if evrything is ok
$query = "UPDATE skill SET name='".$name."', updated='".$updated."', guideby='".$guideby."', contributors='".$contributors."', members='".$members."', mainbody='".$guide."', sorter='".$sorter."' WHERE id='".$id."'";
$result = mysql_query ($query); //Run the query.
if ($result){ //if it entered correctly
echo '<br /><table width=98% bgcolor=#C6F4DF class=pass align=center><tr>
<td width=40><img src=images/tick.gif></td>
<td align=left>
<B>Success</B> <BR>
The skill guide for '.$name.' was successfully updated<br />
</table><br /><br />';
include ('footer.inc');//footer
exit();
}else{ // didn't work
echo '<table width=98% bgcolor=#faf5f4 class=logfail align=center><tr>
<td width=40><img src=images/exclamation.gif></td>
<td align=left>
<B>Update Failed!</B> <BR>
The skill guide for '.$name.' could not be updated
<BR>Please Try again later<br />
</table><br /><br />';
//Name: '.$name.' Updated: '.$updated.' Contributors: '.$contributors.' By: '.$guideby.' Members: '.$members.' Guide: '.$guide.'
}
}
}
/* query for item */
$query = "SELECT * FROM skill WHERE id=".$id;
$result = mysql_query ($query);
/* if we get no results back, error out */
$numrtn = mysql_num_rows($result);
if ($numrtn == 0) {
echo "The guide requested cannot be found\n";
return;
}
$row = mysql_fetch_assoc($result);
/* easier to read variables and
* striping out tags */
$nid = $id;
$title = $row['name'];
$guideby = $row['guideby'];
$members = ucwords($row['members']);
$guide = $row['mainbody'];
$sorter = $row['sorter'];
echo '<br /><font class="adminheader"><center>Update skill guide</center></font><br />
Here you can update an existing skill guides in the database.<br />
<center><form action="admin2.php?flibble=update_s&id='.$nid.'" method="post">
<table class=calc>
<tr><td>
<table>
<tr><td align=right><font class="text2">Skill Name:</font></td><td align=left><input type="text" class="text" name="name" size="15" maxlength="30" value="'.$title.'" /></td></tr>
<tr><td align=right><font class="text2">Guide Written by:</font></td><td align=left><input type="text" class="text" name="guideby" size="15" maxlength="30" value="'.$guideby.'" /></td></tr>
<tr><td align=right><font class="text2">Members?:</font></td><td align=left><input type="text" class="text" name="members" size="1" maxlength="1" value="'.$members.'<font class="small2">Use Y or N only</font></td></tr>
<tr><td align=right><font class="text2">Main Guide:</font></td><td align=left><textarea name="guide" cols="50" rows="18" wrap=physical>'.$guide.'</textarea></td></tr>
<tr><td align=right><font class="text2">Contributors:</font></td><td align=left><input type="text" class="text" name="contributors" size="30" maxlength="255" value="'.$contributors.'" /></td></tr>
<tr><td align=right><font class="text2">Sort name:</font></td><td align=left><input type="text" class="text" name="sorter" size="30" maxlength="255" value="'.$sorter.'" /><font class="small2">This is the name of the skill without spaces or the leading "The" if it has one.</font></td></tr>
</table>
</td>
</tr>
<tr>
<td>
<div align="center"><input type="submit" name="submit" value="Update Skill Guide" class="liteoption"/> <input type="submit" name="preview" value="Preview" class="liteoption"/> <input type="reset" name="reset" value="reset" class="liteoption" /></div>
</td>
</tr>
</table>
</CENTER>
</form>';
}
function add_skill() {
if (isset($_POST['preview'])){ //handle form
$name = $_POST['name'];
$contributors = $_POST['contributors'];
$guideby = $_POST['guideby'];
$members = $_POST['members'];
$guide = $_POST['guide'];
if ($members = "Y") {
$mem = "members only skill</b>, so it can only be done on a <b>members</b> server.";
}else{
$mem = "non-members skill</b>.";
}
if ($updated == 0){
$up = 'No-one has updated this skill guide';
}else{
$date2 = date("l jS of F Y @ H:i:s ", $updated);
$up = 'It was last updated on '.$date2.'.';
}
if ($contributors != ""){
$con = 'Thanks also to <b>'.$contributors.'</b> for changes.';
}else{
$con = 'No-one else has contributed to this skill guide';
}
//$date = date("D M jS, Y g:i a", $added);
$date = date("l jS of F Y @ H:i:s ", $added);
echo '
<p class="skillheader">'.$name.'</p>
<p>This skill guide was written by <b>'.$guideby.'</b> for use on Runehints. '.$con.' <br /></p>
<p class="small2"><br />This skill is <b>'.$mem.'</p>
<p class="small2">'.$guide.'</p>'
;
}
if (isset($_POST['submit'])){ //handle form;
require_once ('../mysql_connect.php');//connect to db
$name = $_POST['name'];
$guideby = $_POST['guideby'];
$members = $_POST['members'];
$guide = $_POST['guide'];
$added = time();
$sorter = $_POST['sorter'];
if ($name){//if evrything is ok
$query = "INSERT INTO skill (name, added, guideby, members, mainbody, sorter) VALUES ('$name', '$added', '$guideby', '$members', '$guide', '$sorter')";
$result = mysql_query ($query); //Run the query.
if ($result){ //if it entered correctly
echo '<br /><table width=98% bgcolor=#C6F4DF class=pass align=center><tr>
<td width=40><img src=images/tick.gif></td>
<td align=left>
<B>Success</B> <BR>
The skill guide for '.$name.' was successfully added<br />
</table><br /><br />';
include ('footer.inc');//footer
exit();
}else{ // didn't work
echo '<table width=98% bgcolor=#faf5f4 class=logfail align=center><tr>
<td width=40><img src=images/exclamation.gif></td>
<td align=left>
<B>Update Failed!</B> <BR>
The skill guide for '.$name.' could not be added
<BR>Please Try again later<br />
</table><br /><br />';
}
}
}
?>
<br /><font class="adminheader"><center>Add skill guides</center></font><br />
Here you can add skill guides to the database.<br />
<form action="admin2.php?flibble=add_s" method="post"><center>
<table class=calc>
<tr><td>
<table>
<tr><td align=right><font class="text2">Skill Name:</font></td><td align=left><input type="text" class="text" name="name" size="15" maxlength="50" value="<?php if (isset($_POST['name'])) echo stripslashes($_POST['name']); ?>" /></td></tr>
<tr><td align=right><font class="text2">Guide Written by:</font></td><td align=left><input type="text" class="text" name="guideby" size="15" maxlength="30" value="<?php if (isset($_POST['guideby'])) echo stripslashes($_POST['guideby']); ?>" /></td></tr>
<tr><td align=right><font class="text2">Members?:</font></td><td align=left><input type="text" class="text" name="members" size="1" maxlength="1" value="<?php if (isset($_POST['members'])) echo stripslashes($_POST['members']); ?>" /><font class="small2">Use Y or N only</font></td></tr>
<tr><td align=right><font class="text2">Main Guide:</font></td><td align=left><textarea name="guide" cols='50' rows='18' wrap=physical><?php if (isset($_POST['guide'])) echo stripslashes($_POST['guide']); ?></textarea> <font class="small2"> When including, bold, italics, images etc. Please use <a href="html.php" target="_blank">HTML</a></font></td></tr>
<tr><td align=right><font class="text2">Sort Name:</font></td><td align=left><input type="text" class="text" name="sorter" size="30" maxlength="255" value="<?php if (isset($_POST['sorter'])) echo stripslashes($_POST['sorter']); ?>" /><font class="small2">This is the name of the skill without spaces or the leading "The" if it has one.</font></td></tr>
</table>
</td>
</tr>
<tr>
<td>
<div align="center"><input type="submit" name="submit" value="Add Skill Guide" class="liteoption" /> <input type="submit" name="preview" value="Preview" class="liteoption" /> <input type="reset" name="reset" value="reset" class="liteoption" /></div>
</td>
</tr>
</table>
</CENTER>
</form>
<?php
}
function delete_s($id){
$query = "SELECT `name` FROM skill WHERE id=$id";
$result = mysql_query ($query);
/* if we get no results back, error out */
$numrtn = mysql_num_rows($result);
if ($numrtn == 0) {
echo "The skill guide requested cannot be found\n";
return;
}
$row = mysql_fetch_assoc($result);
/* easier to read variables and
* striping out tags */
$name = $row['name'];
if (isset($_POST['yes'])){ //handle form
$query = "DELETE FROM `skill` WHERE `id` = ".$id." LIMIT 1";
$result = mysql_query($query);
if ($result) {
ob_end_clean();
header("http://runehints.com/admin2.php?flibble=skill");
exit();
}
}
if (isset($_POST['no'])) {
ob_end_clean();
header("http://runehints.com/admins.php?flibble=skill");
exit();
}
echo '<table width=98% bgcolor=#faf5f4 class=logfail align=center><tr>
<td width=40><img src=images/exclamation.gif></td>
<td align=left>
<B>Delete?</B> <BR>
Are you sure you want to delete '.$name.' from the database?
<BR><br /><form action="admin2.php?flibble=delete_s&id='.$id.'" method="post"><input type="submit" name="yes" value="Yes" class="delete" /> <input name="no" type="submit" value="No" class="delete" /></form>
</table><br /><br />';
}
//------------------------End skill-------------------------------------------//Code: Select all
--
-- Table structure for table `skill`
--
CREATE TABLE `skill` (
`id` int(10) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
`added` int(11) NOT NULL default '0',
`guideby` varchar(30) NOT NULL default '',
`contributors` varchar(225) NOT NULL default '',
`members` char(1) NOT NULL default 'N',
`mainbody` text NOT NULL,
`updated` int(11) NOT NULL default '0',
`sorter` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=8 ;