|
Content managment system
i have been following the cms tutorial posted on your forum has helped me gain a good knowledge in php and mySQL now the problem i have is i am trying to develop a code to edit articles now almost the whole code works apart from the submit part of the code when i login to edit the sections i displays the data alows me to edit the data when i click submit it should post the new querys to mySQL insted it just takes me back to the editArticle.php page, Can anybody help please
Here is the code
<?php
require_once("../includes/Sentry.php");
$sentry = new Sentry();
if ($HTTP_POST_VARS['user'] != ''){
$sentry->checkLogin($HTTP_POST_VARS['user'],$HTTP_POST_VARS['pass'],4,'welcome.php','failed.php');
}
if ($HTTP_GET_VARS['action'] == 'logout'){
if ($sentry->logout()){
echo '<center>You have been logged out</center><br>';
}
}
?>
<?
// Require the classes
require_once('../includes/DbConnector.php');
require_once('../includes/Validator.php');
// Create an object (instance) of the DbConnector and Validator
$connector = new DbConnector();
$validator = new Validator();
//select which database you want to edit
mysql_select_db("web176-contentms");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the thearticle
$result = mysql_query("select * from cmsarticles order by id");
//run the while loop that grabs all the thearticle scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the thearticle
$title=$r["title"];//take out the title
$id=$r["ID"];//take out the id
//make the title a link
echo "<a href='editArticle.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["Submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM cmsarticles WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="editArticle.php" method="post">
<input type=hidden name="ID" value="<?php echo $myrow["id"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="thearticle" ROWS=10 COLS=30><? echo $myrow["thearticle"] ?></TEXTAREA>
<br>
<input type="hidden" name="cmd" value="edit">
<input type="Submit" name="Submit" value="Submit">
</form>
<? } ?>
<?
if ($_POST["$Submit"])
{
$title = $_POST["title"];
$thearticle = $_POST["thearticle"];
$sql = "UPDATE cmsarticles SET title='$title',thearticle='$thearticle' WHERE id=$id";
//replace theArticles with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
|