Jump to content

Admin script not working with forms...


ShadeSlayer

Recommended Posts

I have this admin script for a project I'm doing and anything that actually involves a form doesn't work while other things do.

 

I've included comments in this script, they show what works and what doesn't work...

 

<?php
ob_start("ob_gzhandler");
/* Readerboard Management File
* Script by Alex Crooks
* Copyright 2009, protected under Creative Commons Licence
*/
include("config.php");
$functionset = "admin";

if($_GET['page'] == "content")
{
$pagetitle = "Manage Content";
$output = "This page is for managing your base content. You may add, edit, or delete them. Choose an appropriate graphic that corresponds to what you'd like to do.<br /><br />\n"
         ."<table width=\"100%\" border=\"1\" bgcolor=\"#ffffff\">\n"
         ."<tr align=\"center\">\n"
         ."<td><b>ID</b></td>\n"
         ."<td><b>Title</b></td>\n"
         ."<td style=\"width: 30px;\"><b>Edit</b></td>\n"
         ."<td style=\"width: 30px;\"><b>Delete</b></td>\n"
         ."</tr>\n";

$sql = "SELECT * FROM ".TABLE_CONTENT." ORDER BY ID ASC";
if($exe = mysql_query($sql))
{
  while($row = mysql_fetch_array($exe)) // This one works, displays the content just fine...
  {
  $row['editlink'] = "<a href=\"".$_SERVER['PHP_SELF']."?page=content&action=edit&wid=".$row['ID']."\"><img style=\"width: 25px; height: 25px;\" src=\"edit.png\" /></a>";
  $row['deletelink'] = "<a href=\"".$_SERVER['PHP_SELF']."?page=content&action=delete&wid=".$row['ID']."\"><img style=\"width: 25px; height: 25px;\" src=\"delete.png\" /></a>";
  $output .= "<tr>\n"
            ."<td>".$row['ID']."</td>\n"
            ."<td>".stripslashes($row['title'])."</td>\n"
            ."<td>".$row['editlink']."</td>\n"
            ."<td>".$row['deletelink']."</td>\n"
            ."</tr>\n";
  }
}
$output .= "</table><br /><br />\n"
          ."<a href=\"".$_SERVER['PHP_SELF']."?page=content&action=add\"><img style=\"width: 25px; height: 25px;\" src=\"add.png\" /> Add New</a>\n";

if($_GET['action'] == "add") // This one doesn't work, when you click on the submit button it goes to the main page (without an action) instead of do=process and doesnt execute the proper function
{
$output = "<form action=\"".$_SERVER['PHP_SELF']."\">\n"
          ."<b>Title:</b> <input type=\"text\" name=\"title\" value=\"\" /><br />\n"
          ."<b>Content:</b><textarea style=\"width: 100%; height: 100px;\" name=\"body\" value=\"\"></textarea><br /><br />\n"
		  ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
          ."<input type=\"submit\" />\n"
	  ."</form>\n";
  if($_POST['do'] == "process") // Page never gets to here for some reason.
  {
  $sql = "INSERT INTO ".TABLE_CONTENT." (title, body) VALUES ('".addslashes($_POST['title'])."', '".addslashes($_POST['body'])."')";
   if($exe = mysql_query($sql))
   {
   $output = "Content item successfully added.\n";
   }
  }
}
if($_GET['action'] == "edit") // Page doesn't display the value in the text area, but does display the value in the title. Again, submit button goes to main page instead of do=process and doesn't execute the proper function
{
$sql = "SELECT * FROM ".TABLE_CONTENT." WHERE ID = '".$_GET['wid']."'";
$row = mysql_fetch_array(mysql_query($sql));
$output = "<form action=\"".$_SERVER['PHP_SELF']."\">\n"
          ."<b>Title:</b> <input type=\"text\" name=\"title\" value=\"".stripslashes($row['title'])."\" /><br />\n"
          ."<b>Content:</b><textarea style=\"width: 100%; height: 100px;\" name=\"body\" value=\"".stripslashes($row['body'])."\"></textarea><br /><br />\n"
	  ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
          ."<input type=\"submit\" />\n"
	  ."</form>\n";
  if($_POST['do'] == "process") // This gets skipped for some reason.
  {
  $sql = "UPDATE ".TABLE_CONTENT." SET title = '".addslashes($_POST['title'])."', body = '".addslashes($_POST['body'])."' WHERE ID = '".$_GET['wid']."'";
   if($exe = mysql_query($sql))
   {
   $output = "Content item #".$_GET['wid']." successfully updated.\n";
   }
  }
}
if($_GET['action'] == "delete") // This works just fine, displays "content item #whatever successfully removed.
{
$sql = "DELETE FROM ".TABLE_CONTENT." WHERE ID = '".$_GET['wid']."'";
  if($exe = mysql_query($sql))
  {
  $output = "Content item #".$_GET['wid']." successfully removed.\n";
  }
}
}
if($_GET['page'] == "messages") 
{
$pagetitle = "Manage Messages";
$output = "This page is for managing your messages. You may add, edit, or delete them. Choose an appropriate graphic that corresponds to what you'd like to do.\n"
         ."<table width=\"100%\" border=\"1\" bgcolor=\"#ffffff\">\n"
         ."<tr align=\"center\">\n"
         ."<td><b>ID</b></td>\n"
         ."<td><b>Name</b></td>\n"
         ."<td style=\"width: 30px;\"><b>Edit</b></td>\n"
         ."<td style=\"width: 30px;\"><b>Delete</b></td>\n"
         ."</tr>\n";

$sql = "SELECT * FROM ".TABLE_MESSAGES." ORDER BY ID ASC";
if($exe = mysql_query($sql))
{
  while($row = mysql_fetch_array($exe)) // this displays everything just fine
  {
  $row['editlink'] = "<a href=\"".$_SERVER['PHP_SELF']."?page=messages&action=edit&wid=".$row['ID']."\"><img style=\"width: 25px; height: 25px;\" src=\"edit.png\" /></a>";
  $row['deletelink'] = "<a href=\"".$_SERVER['PHP_SELF']."?page=messages&action=delete&wid=".$row['ID']."\"><img style=\"width: 25px; height: 25px;\" src=\"delete.png\" /></a>";
  $output .= "<tr>\n"
            ."<td>".$row['ID']."</td>\n"
            ."<td>".stripslashes($row['name'])."</td>\n"
            ."<td>".$row['editlink']."</td>\n"
            ."<td>".$row['deletelink']."</td>\n"
            ."</tr>\n";
  }
}
$output .= "</table><br /><br />\n"
          ."<a href=\"".$_SERVER['PHP_SELF']."?page=messages&action=add\"><img style=\"width: 25px; height: 25px;\" src=\"add.png\" /> Add New</a>\n";

if($_GET['action'] == "add") // The add page doesn't execute the script and goes to the manage.admin.php instead of ...&do=process
{
$output = "<form action=\"".$_SERVER['PHP_SELF']."\">\n"
          ."<b>Name:</b> <input type=\"text\" name=\"name\" value=\"\" />\n"
		  ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
          ."<input type=\"submit\" />\n"
	  ."</form>";
  if($_POST['do'] == "process") // This gets skipped for some reason.
  {
  $sql = "INSERT INTO ".TABLE_MESSAGES." (name) VALUES ('".addslashes($_POST['name'])."')";
   if($exe = mysql_query($sql))
   {
   $output = $_POST['name']." successfully added to the messages.\n";
   }
  }
}
if($_GET['action'] == "edit") // The textbox displays the value of whatever name you're editing, but it doesn't execute.
{
$sql = "SELECT * FROM ".TABLE_MESSAGES." WHERE ID = '".$_GET['wid']."'";
$row = mysql_fetch_array(mysql_query($sql));
$output = "<form action=\"".$_SERVER['PHP_SELF']."\">\n"
          ."<b>Name:</b> <input type=\"text\" name=\"name\" value=\"".stripslashes($row['name'])."\" />\n"
	  ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
          ."<input type=\"submit\" />\n"
	  ."</form>\n";
  if($_POST['do'] == "process") // This gets skipped
  {
  $sql = "UPDATE ".TABLE_MESSAGES." SET name = '".addslashes($_POST['name'])."' WHERE ID = '".$_GET['wid']."'";
   if($exe = mysql_query($sql))
   {
   $output = $_POST['name']." successfully updated.\n";
   }
  }
}
if($_GET['action'] == "delete") // Works perfectly
{
$sql = "DELETE FROM ".TABLE_MESSAGES." WHERE ID = '".$_GET['wid']."'";
  if($exe = mysql_query($sql))
  {
  $output = $_POST['name']." successfully removed from the messages.\n";
  }
}
}
if($_GET['page'] == "status") // The little dot in the radio button isn't displayed on whatever is set in the database.. doesn't execute
{
$pagetitle = "Manage Status";
$sql = "SELECT ID, status FROM ".TABLE_SETTINGS." WHERE ID = '1'";
$row = mysql_fetch_array(mysql_query($sql));
$row['status'] = $s;
$output =  "This page is for managing the readerboard status.<br /><br />\n"
          ."<b>Readerboard Status:</b><br />\n"
          ."<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n"
	  ."<input type=\"radio\" name=\"stat\" value=\"1\" ";
	  if($s == "1")
	  {
$output .= "selected=\"selected\"";
          }
$output .= "/> Enabled\n"
	  ."<input type=\"radio\" name=\"stat\" value=\"0\" ";
	  if($s == "0")
	  {
$output .= "selected=\"selected\"";
          }
$output .= "/> Disabled \n"
	  ."<input type=\"hidden\" name=\"do\" value=\"process\" /><br /><br />\n"
          ."<input type=\"submit\" />\n"
	  ."</form>\n";
if($_POST['do'] == "process") // This gets skipped
{
$sql = "UPDATE ".TABLE_SETTINGS." SET status = '".$_POST['stat']."'";
  if($exe = mysql_query($sql))
  {
  $output = "Query Successful.\n";
  }
}
}
if($_GET['page'] == "stylesheet") // Nothing gets displayed in the textarea, doesn't execute
{
$pagetitle = "Manage Stylesheet";
$output = "This page is for managing your stylesheet and banner. Don't edit the stylesheet unless you are experienced with the code.\n";
$sql = "SELECT stylesheet FROM ".TABLE_SETTINGS;
$row = mysql_fetch_array(mysql_query($sql));

$output  .= "<form action=\"".$_SERVER['PHP_SELF']."\">\n"
         ."<textarea style=\"width: 90%; height: 200px;\" name=\"stylesheet\" value=\"".$row['stylesheet']."\"></textarea><br /><br />\n"
         ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
	 ."<input type=\"submit\" />\n";
if($_POST['do'] == "process") // Gets skipped
{
$sql = "UPDATE ".TABLE_SETTINGS." SET stylesheet = '".$_POST['stylesheet']."'";
  if($exe = mysql_query($sql))
  {
  $output = "Stylesheet successfully updated.\n";
  }
}
}
if(($_GET['page'] == "") || (!$_GET['page'])) // When the Submit button is pressed, everything seems to come here...
{
$pagetitle = "Management Page";
$output = "Welcome to the Readerboard management page. Please choose an option to your left.<br /><br />\n"
         ."<b>Manage Content:</b><br />\n"
	 ."Allows you to add, edit, or delete any piece of main content. Also includes a format bar to edit various information (and include pictures).<br /><br />\n"
	 ."<b>Manage Messages:</b><br />\n"
	 ."Allows you to add, edit, or delete the messages at the office for people. Also includes a color bar to edit the color of the text.<br /><br />\n"
	 ."<b>Manage Status:</b><br />\n"
	 ."Allows you to edit whether or not the readerboard is live.<br /><br />\n"
	 ."<b>Manage Stylesheet:</b><br />\n"
	 ."Allows you to edit the banner and style of the readerboard.\n";
}

$pagecontents = $output;
include("layout.php");
?>ggggh

Link to comment
https://forums.phpfreaks.com/topic/159736-admin-script-not-working-with-forms/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.